当前位置: 首页>>代码示例>>Java>>正文


Java Dictionary类代码示例

本文整理汇总了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...");
	}
 
开发者ID:Noahs-ARK,项目名称:semafor-semantic-parser,代码行数:18,代码来源:WordNetAPI.java

示例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; }
}
 
开发者ID:nchambers,项目名称:probschemas,代码行数:27,代码来源:WordNet.java

示例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;
}
 
开发者ID:nchambers,项目名称:schemas,代码行数:25,代码来源:BasicEventAnalyzer.java

示例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;
    }
}
 
开发者ID:dkmfbk,项目名称:pikes,代码行数:22,代码来源:WordNet.java

示例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;
}
 
开发者ID:nikolamilosevic86,项目名称:TableDisentangler,代码行数:25,代码来源:ConceptizationStats.java

示例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();
    } 
}
 
开发者ID:duguyue100,项目名称:chomsky,代码行数:26,代码来源:Wordnet30SynsetTest.java

示例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]));
  }
}
 
开发者ID:Network-of-BioThings,项目名称:GettinCRAFTy,代码行数:20,代码来源:VerbImpl.java

示例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;
}
 
开发者ID:Network-of-BioThings,项目名称:GettinCRAFTy,代码行数:20,代码来源:WordSenseImpl.java

示例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;
}
 
开发者ID:Network-of-BioThings,项目名称:GettinCRAFTy,代码行数:22,代码来源:JWNLWordNetImpl.java

示例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();
	}
}
 
开发者ID:SI3P,项目名称:supWSD,代码行数:14,代码来源:JWNLLemmatizer.java

示例11: unload

import net.didion.jwnl.dictionary.Dictionary; //导入依赖的package包/类
@Override
public void unload() {

	if(mDictionary!=null)
	mDictionary.close();
	
	if(mInit){
		Dictionary.uninstall();
		JWNL.shutdown();
	}
}
 
开发者ID:SI3P,项目名称:supWSD,代码行数:12,代码来源:SensEvalMNS.java

示例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");
}
 
开发者ID:kostagiolasn,项目名称:NucleosomePatternClassifier,代码行数:8,代码来源:Examples.java

示例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));
}
 
开发者ID:kostagiolasn,项目名称:NucleosomePatternClassifier,代码行数:9,代码来源:Examples.java

示例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;
}
 
开发者ID:nchambers,项目名称:probschemas,代码行数:36,代码来源:WordNet.java

示例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;
}
 
开发者ID:nchambers,项目名称:probschemas,代码行数:36,代码来源:WordNet.java


注:本文中的net.didion.jwnl.dictionary.Dictionary类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。