本文整理汇总了Java中net.didion.jwnl.dictionary.Dictionary类的典型用法代码示例。如果您正苦于以下问题:Java Dictionary类的具体用法?Java Dictionary怎么用?Java Dictionary使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Dictionary类属于net.didion.jwnl.dictionary包,在下文中一共展示了Dictionary类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: WordNetAPI
import net.didion.jwnl.dictionary.Dictionary; //导入依赖的package包/类
private WordNetAPI(String propsFile) throws Exception {
info("Initialize WordNet...: ");
if (propsFile == null)
throw new RuntimeException("Missing required property 'WN_PROP'");
try {
JWNL.initialize(new FileInputStream(propsFile));
wDict = Dictionary.getInstance();
pUtils = PointerUtils.getInstance();
morphProcessor = wDict.getMorphologicalProcessor();
} catch (Exception e) {
throw new RuntimeException("Initialization failed", e);
}
info("Done initializing WordNet...");
}
示例2: stringTypes
import net.didion.jwnl.dictionary.Dictionary; //导入依赖的package包/类
/**
* Lookup the word in WordNet
* @returns Array of three strings: word, lemma, synset
*/
public static String[] stringTypes(String str) {
try {
String[] types = new String[3];
String[] parts = str.split("\\s+");
IndexWord iword = Dictionary.getInstance().lookupIndexWord(POS.VERB, parts[parts.length-1]);
if( iword == null )
iword = Dictionary.getInstance().lookupIndexWord(POS.NOUN, parts[parts.length-1]);
if( iword == null ) {
types[1] = parts[parts.length-1];
types[2] = "-1";
}
else {
String lemma = iword.getLemma();
if( lemma.indexOf(' ') != -1 ) // Sometimes it returns a two word phrase
lemma = lemma.trim().replace(' ','-');
types[1] = lemma;
types[2] = Long.toString(iword.getSense(1).getOffset());
}
types[0] = parts[parts.length-1];
return types;
} catch( Exception ex ) { ex.printStackTrace(); return null; }
}
示例3: isVerb
import net.didion.jwnl.dictionary.Dictionary; //导入依赖的package包/类
/**
* @param word A Word
* @return True if the word can be a verb according to WordNet
*/
private boolean isVerb(String word) {
// save time with a table lookup
if( wordToVerb.containsKey(word) )
return wordToVerb.get(word);
try {
IndexWord iword = Dictionary.getInstance().lookupIndexWord(POS.VERB, word);
if( iword == null ) {
wordToVerb.put(word, false);
return false;
}
else {
wordToVerb.put(word, true);
return true;
}
} catch( Exception ex ) { ex.printStackTrace(); }
return false;
}
示例4: getDictionary
import net.didion.jwnl.dictionary.Dictionary; //导入依赖的package包/类
private static Dictionary getDictionary() {
synchronized (WordNet.class) {
if (dictionary == null) {
JWNL.shutdown(); // in case it was previously initialized
try {
final String properties = Resources.toString(
WordNet.class.getResource("jwnl.xml"), Charsets.UTF_8).replace(
"DICTIONARY_PATH_PLACEHOLDER", dictionaryPath);
final InputStream stream = new ByteArrayInputStream(
properties.getBytes(Charsets.UTF_8));
JWNL.initialize(stream);
dictionary = Dictionary.getInstance();
} catch (final Throwable ex) {
JWNL.shutdown();
throw new Error("Cannot initialize JWNL using dictionary path '"
+ dictionaryPath + "'", ex);
}
}
return dictionary;
}
}
示例5: wordExistInEnglish
import net.didion.jwnl.dictionary.Dictionary; //导入依赖的package包/类
public static boolean wordExistInEnglish(String word)
{
try{
IndexWord fword = null;
Dictionary dict = Dictionary.getInstance();
fword = dict.lookupIndexWord(POS.NOUN, word);
if(fword!=null)
return true;
fword = dict.lookupIndexWord(POS.ADJECTIVE, word);
if(fword!=null)
return true;
fword = dict.lookupIndexWord(POS.ADVERB, word);
if(fword!=null)
return true;
fword = dict.lookupIndexWord(POS.VERB, word);
if(fword!=null)
return true;
}
catch(Exception ex)
{
return false;
}
return false;
}
示例6: testGetWordSenses
import net.didion.jwnl.dictionary.Dictionary; //导入依赖的package包/类
/**
* Pulls a noun "tank" from the dictionary and checks to see if it has 5 senses.
*
*/
public void testGetWordSenses() {
try {
JWNL.initialize(TestDefaults.getInputStream());
IndexWord word = Dictionary.getInstance().getIndexWord(POS.NOUN, "tank");
assertTrue(word.getSenseCount() == 5);
word = Dictionary.getInstance().getIndexWord(POS.VERB, "eat");
assertTrue(word.getSenseCount() == 6);
word = Dictionary.getInstance().getIndexWord(POS.ADJECTIVE, "quick");
assertTrue(word.getSenseCount() == 6);
word = Dictionary.getInstance().getIndexWord(POS.ADJECTIVE, "big");
assertTrue(word.getSenseCount() == 13);
} catch(JWNLException e) {
fail("Exception in testGetSenses caught");
e.printStackTrace();
}
}
示例7: VerbImpl
import net.didion.jwnl.dictionary.Dictionary; //导入依赖的package包/类
public VerbImpl(Word _word,
Synset _synset,
int _senseNumber,
int _orderInSynset,
boolean _isSemcor,
net.didion.jwnl.data.Verb _jwVerb,
Dictionary _wnDict) {
super(_word,_synset,_senseNumber,_orderInSynset,_isSemcor, _wnDict);
Assert.assertNotNull(_jwVerb);
String[] jwFrames = _jwVerb.getVerbFrames();
this.verbFrames = new ArrayList(jwFrames.length);
for (int i= 0; i< jwFrames.length; i++) {
this.verbFrames.add(new VerbFrameImpl(jwFrames[i]));
}
}
示例8: WordSenseImpl
import net.didion.jwnl.dictionary.Dictionary; //导入依赖的package包/类
public WordSenseImpl(Word _word,
Synset _synset,
int _senseNumber,
int _orderInSynset,
boolean _isSemcor,
Dictionary _wnDict) {
//0.
Assert.assertNotNull(_word);
Assert.assertNotNull(_synset);
Assert.assertNotNull(_wnDict);
this.word = _word;
this.synset = _synset;
this.senseNumber = _senseNumber;
this.orderInSynset = _orderInSynset;
this.isSemcor = _isSemcor;
this.wnDictionary = _wnDict;
}
示例9: init
import net.didion.jwnl.dictionary.Dictionary; //导入依赖的package包/类
/** Initialise this resource, and return it. */
public Resource init() throws ResourceInstantiationException {
if (null == this.propertyUrl) {
throw new ResourceInstantiationException("property file not set");
}
try {
InputStream inProps = this.propertyUrl.openStream();
JWNL.initialize(inProps);
this.wnDictionary = Dictionary.getInstance();
Assert.assertNotNull(this.wnDictionary);
}
catch(Exception e) {
throw new ResourceInstantiationException(e);
}
return this;
}
示例10: unload
import net.didion.jwnl.dictionary.Dictionary; //导入依赖的package包/类
@Override
public void unload() {
this.mCache.clear();
if (mDictionary != null)
mDictionary.close();
if (mInit) {
Dictionary.uninstall();
JWNL.shutdown();
}
}
示例11: unload
import net.didion.jwnl.dictionary.Dictionary; //导入依赖的package包/类
@Override
public void unload() {
if(mDictionary!=null)
mDictionary.close();
if(mInit){
Dictionary.uninstall();
JWNL.shutdown();
}
}
示例12: Examples
import net.didion.jwnl.dictionary.Dictionary; //导入依赖的package包/类
public Examples() throws JWNLException {
ACCOMPLISH = Dictionary.getInstance().getIndexWord(POS.VERB, "accomplish");
DOG = Dictionary.getInstance().getIndexWord(POS.NOUN, "dog");
CAT = Dictionary.getInstance().lookupIndexWord(POS.NOUN, "cat");
FUNNY = Dictionary.getInstance().lookupIndexWord(POS.ADJECTIVE, "funny");
DROLL = Dictionary.getInstance().lookupIndexWord(POS.ADJECTIVE, "droll");
}
示例13: demonstrateMorphologicalAnalysis
import net.didion.jwnl.dictionary.Dictionary; //导入依赖的package包/类
private void demonstrateMorphologicalAnalysis(String phrase) throws JWNLException {
// "running-away" is kind of a hard case because it involves
// two words that are joined by a hyphen, and one of the words
// is not stemmed. So we have to both remove the hyphen and stem
// "running" before we get to an entry that is in WordNet
System.out.println("Base form for \"" + phrase + "\": " +
Dictionary.getInstance().lookupIndexWord(POS.VERB, phrase));
}
示例14: verbToLemma
import net.didion.jwnl.dictionary.Dictionary; //导入依赖的package包/类
/**
* @param word A word
* @return The lemma of the word if it is a verb, null otherwise
*/
public String verbToLemma(String word) {
if( _verbToLemma == null ) _verbToLemma = new HashMap<String, String>();
// save time with a table lookup
if( _verbToLemma.containsKey(word) ) return _verbToLemma.get(word);
try {
// don't return lemmas for hyphenated words
if( word.indexOf('-') > -1 || word.indexOf('/') > -1 ) {
_verbToLemma.put(word, null);
return null;
}
// get the lemma
IndexWord iword = Dictionary.getInstance().lookupIndexWord(POS.VERB, word);
if( iword == null ) {
_verbToLemma.put(word, null);
return null;
}
else {
String lemma = iword.getLemma();
if( lemma.indexOf(' ') != -1 ) // Sometimes it returns a two word phrase
lemma = lemma.trim().replace(' ','_');
_verbToLemma.put(word, lemma);
return lemma;
}
} catch( Exception ex ) { ex.printStackTrace(); }
return null;
}
示例15: adjectiveToLemma
import net.didion.jwnl.dictionary.Dictionary; //导入依赖的package包/类
/**
* @param word A word
* @return The lemma of the word if it is an adjective, null otherwise
*/
public String adjectiveToLemma(String word) {
if( _adjToLemma == null ) _adjToLemma = new HashMap<String, String>();
// save time with a table lookup
if( _adjToLemma.containsKey(word) ) return _adjToLemma.get(word);
try {
// don't return lemmas for hyphenated words
if( word.indexOf('-') > -1 || word.indexOf('/') > -1 ) {
_adjToLemma.put(word, null);
return null;
}
// get the lemma
IndexWord iword = Dictionary.getInstance().lookupIndexWord(POS.ADJECTIVE, word);
if( iword == null ) {
_adjToLemma.put(word, null);
return null;
}
else {
String lemma = iword.getLemma();
if( lemma.indexOf(' ') != -1 ) // Sometimes it returns a two word phrase
lemma = lemma.trim().replace(' ','_');
_adjToLemma.put(word, lemma);
return lemma;
}
} catch( Exception ex ) { ex.printStackTrace(); }
return null;
}