public class PhraseMatcher extends Object
Modifier and Type | Class and Description |
---|---|
private static class |
PhraseMatcher.MatchedPhrases
Holder of a lazily created list of matched phrases
|
static class |
PhraseMatcher.Phrase
Points to a collection of word items (one or more)
which is matches a complete listing in an automat
|
Modifier and Type | Field and Description |
---|---|
private boolean |
ignorePluralForm
Whether this should ignore regular plural/singular form differences when matching
|
private boolean |
matchAll
False to matche the longest phrase, true to match all phrases
|
private boolean |
matchPhraseItems |
private boolean |
matchSingleItems |
private com.yahoo.fsa.FSA |
phraseFSA |
Modifier | Constructor and Description |
---|---|
private |
PhraseMatcher()
For null subclass only
|
|
PhraseMatcher(com.yahoo.fsa.FSA phraseAutomatonFSA,
boolean ignorePluralForm)
Creates a phrase matcher
|
|
PhraseMatcher(String phraseAutomatonFile)
Creates a phrase matcher.
|
|
PhraseMatcher(String phraseAutomatonFile,
boolean ignorePluralForm)
Creates a phrase matcher
|
Modifier and Type | Method and Description |
---|---|
private int |
findPhrasesAtStartpoint(int startIndex,
CompositeItem owner,
PhraseMatcher.MatchedPhrases phrases)
If (!matchAll), finds longest possible phrase starting at the
given index in the owner and adds it to phrases.
|
static PhraseMatcher |
getNullMatcher()
Returns a phrase matcher which (quickly) never matches anything
|
boolean |
isEmpty() |
private boolean |
matches(com.yahoo.fsa.FSA.State state,
String word) |
List<PhraseMatcher.Phrase> |
matchPhrases(Item queryItem)
Finds all phrases (word sequences of length 1 or higher)
of the same index, not negative items of a notitem,
which constitutes a complete entry in the automaton of this matcher
|
private List<PhraseMatcher.Phrase> |
matchSingleItem(TermItem termItem)
Returns null if this word does not match the automaton, a single-item list if it does
|
private void |
recursivelyMatchPhrases(Item item,
PhraseMatcher.MatchedPhrases phrases)
Find matches within a composite
|
void |
setIgnorePluralForm(boolean ignorePluralForm)
Sets whether we should ignore plural/singular form when matching
|
void |
setMatchAll(boolean matchAll)
Sets whether to return the longest matching phrase when there are overlapping matches (default),
or all matching phrases
|
void |
setMatchPhraseItems(boolean matchPhraseItems)
Set whether to match words contained in phrase items as well.
|
void |
setMatchSingleItems(boolean matchSingleItems)
Sets whether single items should be matched and returned as phrase matches.
|
private List<String> |
setReplace(List<String> replaceList,
int index,
String invertedWord)
Adds a replace word at an index, and any required null's to get to this item.
|
private String |
switchForm(String word)
Makes this plural if it is singular and vice-versa
|
private com.yahoo.fsa.FSA phraseFSA
private boolean matchPhraseItems
private boolean matchSingleItems
private boolean ignorePluralForm
private boolean matchAll
private PhraseMatcher()
public PhraseMatcher(String phraseAutomatonFile)
phraseAutomatonFile
- the file containing phrases to matchIllegalArgumentException
- if the file is not foundpublic PhraseMatcher(String phraseAutomatonFile, boolean ignorePluralForm)
phraseAutomatonFile
- the file containing phrases to matchignorePluralForm
- whether we should ignore plural and singular forms as matchesIllegalArgumentException
- if the file is not foundpublic PhraseMatcher(com.yahoo.fsa.FSA phraseAutomatonFSA, boolean ignorePluralForm)
phraseAutomatonFSA
- the fsa containing phrases to matchignorePluralForm
- whether we should ignore plural and singular forms as matchesIllegalArgumentException
- if FSA is nullpublic boolean isEmpty()
public void setMatchPhraseItems(boolean matchPhraseItems)
public void setMatchSingleItems(boolean matchSingleItems)
public void setIgnorePluralForm(boolean ignorePluralForm)
public void setMatchAll(boolean matchAll)
public List<PhraseMatcher.Phrase> matchPhrases(Item queryItem)
queryItem
- the root query item in which to match phrasesprivate List<PhraseMatcher.Phrase> matchSingleItem(TermItem termItem)
private boolean matches(com.yahoo.fsa.FSA.State state, String word)
private void recursivelyMatchPhrases(Item item, PhraseMatcher.MatchedPhrases phrases)
private int findPhrasesAtStartpoint(int startIndex, CompositeItem owner, PhraseMatcher.MatchedPhrases phrases)
private List<String> setReplace(List<String> replaceList, int index, String invertedWord)
private String switchForm(String word)
public static PhraseMatcher getNullMatcher()
Copyright © 2018. All rights reserved.