Lexical Tools

SPT - Synonyms Mapping Design

I. Introduction
Synonyms mapping uses synonyms source as database mechanism:

  • Vector<SynonymObj> to keep all synonym information
  • Hashtable<String, Vector<Integer>> to keep the indexes of each word

II. Java Classes

  • MappedSynonym.java: a Java object for mapped synonym: synonym|history|depth
    • synonym: the mapped synonym
    • history: the complete (recursive) path of mapping
    • depth: the depth of recursive mapping
      • 0 is itself
      • 1 is non-recursive
  • SynonymsMapping.java: used to find synonyms by simple mapping and recursive mapping

II. Simple Synonyms Mapping

  • lowercase the input word to inWordLc
  • if synonymIndex_ contains inWordLc
    • Get all indexes of inWordLc from synonymIndex_
    • Get all mapped synonyms from synonymList_ by index
    • Instantiate mapped synonyms
      • synonym: mapped string from synonymList_ by index
      • history: inWordLc (the in word)
      • depth: 1
    • Add the mapped synonyms to results

III. Recursive Synonyms Mapping

    Init rSynonyms

  • lowercase the input word to inWordLc
  • Instantiate a mapped synonym for inWordLc
    • synonym: inWordLc
    • history: inWordLc
    • depth: 0 (itself)
  • Initialize results, Vector<MappedSynonym> rSynonyms
  • Add above mapped synonym to rSynonyms

    FindRecursiveSynonyms

  • update rHistory
  • update rDepth
  • Find simple mapped synonyms for the inWordLc
  • if maxDepth is no limit or >= depth, go through all simple mapped synonyms
    • if rSynonyms does not contain found simple mapped synonym
      • update rHistory & rDepth to found simple mapped synonym
      • add found simple mapped synonym to rSynonyms
      • recursively doing these step (call FindRecursiveSynonyms)

    Clean up rSynonyms

  • remove the first element (inWordLc) in rSynonyms

III. Examples

III.1 Synonyms:

Vector<SynonymObj> synonymList_

indexwordsynonym
0dogcanine
1caninedog
2catfeline
3felinecat
4caninemut
5mutcanine

Hashtable<String, Vector<Integer>> synonymIndex_

keyValues
dog[0]
canine[1, 4]
cat[2]
feline[3]
mut[5]

III.2 Simple synonym mapping for "Dog"

  • "Dog" is lowerCase to "dog"
  • Find the indexes from synonymIndex_: [0]
  • Find the mapped synonym from synonymList_:
    • {canine|1|dog}

III.3 Recursive synonym mapping for "Dog"

  • "Dog" is lowerCase to "dog"
  • Add {dog|0|} to rSynonyms
  • Find the mapped synonym of dog: {canine|1|dog}
    => Add into rSynonyms since "canine" does not exist in rSynonyms
    • Find the mapped synonym of canine: {dog|2|canine}
      => Do nonthing since "dog" exists in rSynonyms
    • Find the mapped synonym of canine: {mut|2|canine}
      => Add into rSynonyms since "mut" does not exist in rSynonyms
      • Find the mapped synonym of mut: {canine|3|canine -> mut}
        => Do nonthing since "canine" exists in rSynonyms
  • Remove the first element, {dog|0|}, from rSynonyms
  • The final results of rSynonyms for "Dog" are:
    • {canine|1|dog}
    • {mut|2|canine}