Twease

edu.cornell.med.icb.synonyms.engine
Class SynonymEngine

java.lang.Object
  extended by edu.cornell.med.icb.synonyms.engine.SynonymEngine

public final class SynonymEngine
extends Object

Enging for persisting and recalling Synonyms.

Author:
Kevin Dorff

Field Summary
static String ANY_APPLIES_TO
          Perform reverseLookup should be false on findSynonym.
static String ANY_SOURCE
          Perform reverseLookup should be false on findSynonym.
static boolean DONT_INCLUDE_ALL
          Include all appliesTo should be false on findSynonym.
static boolean INCLUDE_ALL
          Include all appliesTo should be true on findSynonym.
static boolean NO_REVERSE_LOOKUP
          Perform reverseLookup should be false on findSynonym.
static boolean REVERSE_LOOKUP
          Perform reverseLookup should be true on findSynonym.
 
Constructor Summary
SynonymEngine(String persistenceUnitVal)
          Create a new synonym engine for a specific persistence-unit name.
 
Method Summary
 void addEmptySynonym(EmptySynonym emptySynonym)
          Add a new empty synonym.
 void addSynonym(Synonym synonym)
          Add a new synonym.
 void addSynonyms(List<Synonym> synonyms)
          Add a new set of synonyms.
 void close()
          Close the synonym engine.
 int dropAllSynonyms()
          Drops all synonyms for a specific source.
 int dropSource(String source)
          Drops all synonyms for a specific source.
 boolean emptySynonymExists(EmptySynonym emptySynonym)
          Check if an emptySynonym has been persisted emptySynonym.
 List<EmptySynonym> findEmptySynonyms(String dictionaryWord, String source, String appliesTo)
          Find a list of synonyms for a specific dinctionary word.
 List<EmptySynonym> findEmptySynonymsMultiSource(String dictionaryWord, String[] sources, String appliesTo)
          Find a list of synonyms for a specific dinctionary word.
 List<Synonym> findSynonyms(String dictionaryWord, String source, String appliesTo, boolean includeAll, boolean reverseLookup)
          Find a list of synonyms for a specific dinctionary word.
 List<Synonym> findSynonymsMultiSource(String dictionaryWord, String[] sources, String appliesTo, boolean includeAll, boolean reverseLookup)
          Find a list of synonyms for a specific dinctionary word.
 textractor.mg4j.io.TextractorWordReader getWordReader()
          Get the TextractorWordReader to use.
static boolean listContainsDictionaryWord(List<Synonym> synonyms, String toFind)
          Searches a list of synonyms.
static boolean listContainsSynonym(List<Synonym> synonyms, Synonym toFind)
          Searches a list of synonyms.
static String processTerm(String termToProcess)
          Use the term processor to process the term or phrase.
 void recreateIndexes()
          Create or re-create the synonym indexes.
 int removeEmptySynonym(EmptySynonym emptySynonym)
          Remove the empty synonym as described here.
static void removeSynonymWord(List<Synonym> syns, String synToRemove)
          Remove all synonyms from the list where the synonymWord is synToExclude.
 void setWordReader(textractor.mg4j.io.TextractorWordReader wordReaderVal)
          Set the TextractorWordReader to use.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

INCLUDE_ALL

public static final boolean INCLUDE_ALL
Include all appliesTo should be true on findSynonym.

See Also:
Constant Field Values

DONT_INCLUDE_ALL

public static final boolean DONT_INCLUDE_ALL
Include all appliesTo should be false on findSynonym.

See Also:
Constant Field Values

REVERSE_LOOKUP

public static final boolean REVERSE_LOOKUP
Perform reverseLookup should be true on findSynonym.

See Also:
Constant Field Values

NO_REVERSE_LOOKUP

public static final boolean NO_REVERSE_LOOKUP
Perform reverseLookup should be false on findSynonym.

See Also:
Constant Field Values

ANY_SOURCE

public static final String ANY_SOURCE
Perform reverseLookup should be false on findSynonym.


ANY_APPLIES_TO

public static final String ANY_APPLIES_TO
Perform reverseLookup should be false on findSynonym.

Constructor Detail

SynonymEngine

public SynonymEngine(String persistenceUnitVal)
Create a new synonym engine for a specific persistence-unit name. The name of the persistence unit comes from the persistence.xml file from [persistence-unit name="xxx"].

Parameters:
persistenceUnitVal - The name of the persistence-unit to use.
Method Detail

setWordReader

public void setWordReader(textractor.mg4j.io.TextractorWordReader wordReaderVal)
Set the TextractorWordReader to use.

Parameters:
wordReaderVal - the word reader to use

getWordReader

public textractor.mg4j.io.TextractorWordReader getWordReader()
Get the TextractorWordReader to use.

Returns:
wordReader the word reader to use

addEmptySynonym

public void addEmptySynonym(EmptySynonym emptySynonym)
Add a new empty synonym.

Parameters:
emptySynonym - The emptySynonyn to add

removeEmptySynonym

public int removeEmptySynonym(EmptySynonym emptySynonym)
Remove the empty synonym as described here.

Parameters:
emptySynonym - the empty synonym to remove
Returns:
the number of emptySynonyms removed

addSynonym

public void addSynonym(Synonym synonym)
Add a new synonym.

Parameters:
synonym - The synonyn to add

recreateIndexes

public void recreateIndexes()
Create or re-create the synonym indexes. For ORACLE.


addSynonyms

public void addSynonyms(List<Synonym> synonyms)
Add a new set of synonyms.

Parameters:
synonyms - The synonyn to add

findSynonymsMultiSource

public List<Synonym> findSynonymsMultiSource(String dictionaryWord,
                                             String[] sources,
                                             String appliesTo,
                                             boolean includeAll,
                                             boolean reverseLookup)
Find a list of synonyms for a specific dinctionary word. This version will create a new entity manager to do the single database call. Supports reverse lookup if no synonyms were returned if reverseLookup set to true.

Parameters:
dictionaryWord - the dictionary to find synonyms for
sources - the "sources" to find all synonyms for, null for all sources
appliesTo - the "appliesTo" to find all synonyms for.
includeAll - wither to also include synonyms where appliesTo equals Synonyms.APPLIES_TO_ALL.
reverseLookup - if true, performs a reverse lookup, ie, search for the requsted dictionaryWord as a synonym, return the synonyms of the the dictionaryWord of that synonym
Returns:
List[Synonym] the list of synonyms that match the request.

findSynonyms

public List<Synonym> findSynonyms(String dictionaryWord,
                                  String source,
                                  String appliesTo,
                                  boolean includeAll,
                                  boolean reverseLookup)
Find a list of synonyms for a specific dinctionary word. This version will create a new entity manager to do the single database call. Supports reverse lookup if no synonyms were returned if reverseLookup set to true.

Parameters:
dictionaryWord - the dictionary to find synonyms for
source - the "source" to find all synonyms for, null for all sources
appliesTo - the "appliesTo" to find all synonyms for.
includeAll - wither to also include synonyms where appliesTo equals Synonyms.APPLIES_TO_ALL.
reverseLookup - if true, performs a reverse lookup, ie, search for the requsted dictionaryWord as a synonym, return the synonyms of the the dictionaryWord of that synonym
Returns:
List[Synonym] the list of synonyms that match the request.

removeSynonymWord

public static void removeSynonymWord(List<Synonym> syns,
                                     String synToRemove)
Remove all synonyms from the list where the synonymWord is synToExclude.

Parameters:
syns - Synonyms list
synToRemove - remove all synonyms from the list where the synonymWord is synToExclude

findEmptySynonyms

public List<EmptySynonym> findEmptySynonyms(String dictionaryWord,
                                            String source,
                                            String appliesTo)
Find a list of synonyms for a specific dinctionary word. This version will create a new entity manager to do the single database call.

Parameters:
dictionaryWord - the dictionary to find synonyms for
source - the "source" to find all synonyms for, null for all sources
appliesTo - the "appliesTo" to find all synonyms for. Synonyms.APPLIES_TO_ALL.
Returns:
List[Synonym] the list of synonyms that match the request.

findEmptySynonymsMultiSource

public List<EmptySynonym> findEmptySynonymsMultiSource(String dictionaryWord,
                                                       String[] sources,
                                                       String appliesTo)
Find a list of synonyms for a specific dinctionary word. This version will create a new entity manager to do the single database call.

Parameters:
dictionaryWord - the dictionary to find synonyms for
sources - the "sources" to find all synonyms for, null for all sources
appliesTo - the "appliesTo" to find all synonyms for. Synonyms.APPLIES_TO_ALL.
Returns:
List[Synonym] the list of synonyms that match the request.

emptySynonymExists

public boolean emptySynonymExists(EmptySynonym emptySynonym)
Check if an emptySynonym has been persisted emptySynonym.

Parameters:
emptySynonym - emptySynonym to lookup
Returns:
true if the emptySynonym has been persisted.

dropSource

public int dropSource(String source)
Drops all synonyms for a specific source.

Parameters:
source - the name of the source to drop synonyms for
Returns:
the number of synonyms dropped

dropAllSynonyms

public int dropAllSynonyms()
Drops all synonyms for a specific source.

Returns:
the number of synonyms dropped

processTerm

public static String processTerm(String termToProcess)
Use the term processor to process the term or phrase. If the wordReader is provided it will use that BEFORE using the term processor. Long terms (or terms within phrases, where terms in a phrase are separated by spaces) will be forced to lower case, short terms will remain mixed case).

Parameters:
termToProcess - term or phrase to process
Returns:
the processed term or phrase

close

public void close()
Close the synonym engine. This should be called when you are finished with the synonym engine (ie, the end of the application).


listContainsSynonym

public static boolean listContainsSynonym(List<Synonym> synonyms,
                                          Synonym toFind)
Searches a list of synonyms. Returns true if the specified synonym is in the list. Note: The isEquivalent function ignores the importDate and id fields otherwise the comparison might not hold up.

Parameters:
synonyms - the list of synonyms to search
toFind - the synonym to look for in the list
Returns:
boolean true if toFind was found in synonyms

listContainsDictionaryWord

public static boolean listContainsDictionaryWord(List<Synonym> synonyms,
                                                 String toFind)
Searches a list of synonyms. Returns true if the specified dictionary word is in the list.

Parameters:
synonyms - the list of synonyms to search
toFind - the dictionary word to look for in the list
Returns:
boolean true if toFind was found in synonyms

Twease

Copyright © 2006-2007 Institute for Computational Biomedicine, All Rights Reserved.