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


Java JWNLException类代码示例

本文整理汇总了Java中net.didion.jwnl.JWNLException的典型用法代码示例。如果您正苦于以下问题:Java JWNLException类的具体用法?Java JWNLException怎么用?Java JWNLException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


JWNLException类属于net.didion.jwnl包,在下文中一共展示了JWNLException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getSynsetsForLemma

import net.didion.jwnl.JWNLException; //导入依赖的package包/类
public static List<String> getSynsetsForLemma(String lemma, String pos) {
    try {
        synchronized (WordNet.class) {
            IndexWord indexWord = getDictionary().lookupIndexWord(POS.getPOSForKey(pos), lemma);
            if (indexWord == null) {
                return new ArrayList<>();
            }
            Synset[] synsets = indexWord.getSenses();
            ArrayList<String> ret = new ArrayList<>();
            for (int i = 0; i < synsets.length; i++) {
                Synset synset = synsets[i];
                ret.add(getSynsetID(synset.getOffset(), synset.getPOS().getKey()));
            }

            return ret;
        }
    } catch (final JWNLException ex) {
        throw new Error(ex);
    }
}
 
开发者ID:dkmfbk,项目名称:pikes,代码行数:21,代码来源:WordNet.java

示例2: getException

import net.didion.jwnl.JWNLException; //导入依赖的package包/类
public Exc getException(POS pos, String derivation) throws JWNLException {
    Exc exc = null;
    if (isCachingEnabled()) {
        exc = getCachedException(new POSKey(pos, derivation));
    }
    if (exc == null) {
        Query query = null;
        try {
            query = _dbManager.getExceptionQuery(pos, derivation);
            exc = _elementFactory.createExc(pos, derivation, query.execute());
            if (exc != null && isCachingEnabled()) {
                cacheException(new POSKey(pos, derivation), exc);
            }
        } catch (SQLException e) {
            throw new JWNLException("DICTIONARY_EXCEPTION_023", e);
        } finally {
            query.close();
        }
    }
    return exc;
}
 
开发者ID:FabianFriedrich,项目名称:Text2Process,代码行数:22,代码来源:DatabaseBackedDictionary.java

示例3: install

import net.didion.jwnl.JWNLException; //导入依赖的package包/类
/**
 * Install a <code>MapBackedDictionary</code> from a map of parameters. The parameters are chosen from the static
 * variables above.
 */
public void install(Map params) throws JWNLException {
	Param param = (Param) params.get(MORPH);
	MorphologicalProcessor morph = (param == null) ? null : (MorphologicalProcessor) param.create();

	param = (Param) params.get(FILE_TYPE);
	Class dictionaryFileType = null;
	try {
		dictionaryFileType = Class.forName(param.getValue());
	} catch (Exception ex) {
		throw new JWNLException("DICTIONARY_EXCEPTION_003", param.getValue(), ex);
	}
	checkFileType(dictionaryFileType);

	param = (Param) params.get(PATH);
	String path = param.getValue();

	install(path, dictionaryFileType, morph);
}
 
开发者ID:FabianFriedrich,项目名称:Text2Process,代码行数:23,代码来源:MapBackedDictionary.java

示例4: isCompoundNoun

import net.didion.jwnl.JWNLException; //导入依赖的package包/类
/**
 * Checks if the word exists as a noun. Supports multi-token terms.
 * 
 * @param word a word
 * @return <code>true</code> iff the word is a noun
 */
public static boolean isCompoundNoun(String word) {
	if (dict == null) return false;
	
	// do not look up words with special characters other than '.'
	if (word.matches(".*?[^\\w\\s\\.].*+")) return false;
	
	IndexWord indexWord = null;
	try {
		indexWord = dict.lookupIndexWord(POS.NOUN, word);
	} catch (JWNLException e) {}
	if (indexWord == null) return false;
	
	// ensure that the word, and not just a substring, was found in WordNet
	int wordTokens = word.split("\\s", -1).length;
	int wordDots = word.split("\\.", -1).length;
	String lemma = indexWord.getLemma();
	int lemmaTokens = lemma.split("\\s", -1).length;
	int lemmaDots = lemma.split("\\.", -1).length;
	return wordTokens == lemmaTokens && wordDots == lemmaDots;
}
 
开发者ID:claritylab,项目名称:lucida,代码行数:27,代码来源:WordNet.java

示例5: findSymmetricRelationships

import net.didion.jwnl.JWNLException; //导入依赖的package包/类
/** A symmetric relationship is one whose type is symmetric (i.e. is it's own inverse). */
private RelationshipList findSymmetricRelationships(
    final Synset sourceSynset, final Synset targetSynset, PointerType type, int depth) throws JWNLException {

	PointerTargetTree tree = new PointerTargetTree(
	    sourceSynset, PointerUtils.getInstance().makePointerTargetTreeList(sourceSynset, type, null, depth, false));

	PointerTargetTreeNodeList.Operation opr = new PointerTargetTreeNodeList.Operation() {
		public Object execute(PointerTargetTreeNode testNode) {
                if (targetSynset.equals(testNode.getSynset())) {
                   
				return testNode;
			}
			return null;
		}
	};
	List l = tree.getAllMatches(opr);

	RelationshipList list = new RelationshipList();
	for (int i = 0; i < l.size(); i++) {
		PointerTargetNodeList nodes = findSymmetricRelationship((PointerTargetTreeNode)l.get(i), type);
		list.add(new SymmetricRelationship(type, nodes, sourceSynset, targetSynset));
	}
	return list;
}
 
开发者ID:FabianFriedrich,项目名称:Text2Process,代码行数:26,代码来源:RelationshipFinder.java

示例6: isCompoundWord

import net.didion.jwnl.JWNLException; //导入依赖的package包/类
/**
 * Checks if the word exists in WordNet. Supports multi-token terms.
 * 
 * @param word a word
 * @return <code>true</code> iff the word is in WordNet
 */
public static boolean isCompoundWord(String word) {
	if (dict == null) return false;
	
	// do not look up words with special characters other than '.'
	if (word.matches(".*?[^\\w\\s\\.].*+")) return false;
	
	IndexWordSet indexWordSet = null;
	try {
		indexWordSet = dict.lookupAllIndexWords(word);
	} catch (JWNLException e) {}
	
	// ensure that the word, and not just a substring, was found in WordNet
	int wordTokens = word.split("\\s", -1).length;
	int wordDots = word.split("\\.", -1).length;
	for (IndexWord indexWord : indexWordSet.getIndexWordArray()) {
		String lemma = indexWord.getLemma();
		int lemmaTokens = lemma.split("\\s", -1).length;
		int lemmaDots = lemma.split("\\.", -1).length;
		if (wordTokens == lemmaTokens && wordDots == lemmaDots) return true;
	}
	return false;
}
 
开发者ID:TScottJ,项目名称:OpenEphyra,代码行数:29,代码来源:WordNet.java

示例7: serialize

import net.didion.jwnl.JWNLException; //导入依赖的package包/类
private void serialize(POS pos, DictionaryFileType fileType)
    throws JWNLException, IOException
{
    ObjectDictionaryFile file = (ObjectDictionaryFile)_destFiles.getDictionaryFile(pos, fileType);
    int count = 0;
    for(Iterator itr = getIterator(pos, fileType); itr.hasNext(); itr.next())
        if(++count % 10000 == 0)
            System.out.println("Counted and cached word " + count + "...");

    Map map = new HashMap((int)Math.ceil((float)count / 0.9F) + 1, 0.9F);
    DictionaryElement elt;
    for(Iterator listItr = getIterator(pos, fileType); listItr.hasNext(); map.put(elt.getKey(), elt))
        elt = (DictionaryElement)listItr.next();

    file.writeObject(map);
    file.close();
    map = null;
    file = null;
    System.gc();
    Runtime rt = Runtime.getRuntime();
    System.out.println("total mem: " + rt.totalMemory() / 1024L + "K free mem: " + rt.freeMemory() / 1024L + "K");
    System.out.println("Successfully serialized...");
}
 
开发者ID:FabianFriedrich,项目名称:Text2Process,代码行数:24,代码来源:DictionaryToMap.java

示例8: testGetWordSenses

import net.didion.jwnl.JWNLException; //导入依赖的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

示例9: getSynset

import net.didion.jwnl.JWNLException; //导入依赖的package包/类
private Synset getSynset(POS pos, long offset, String line) throws JWNLException {
	POSKey key = new POSKey(pos, offset);
	Synset synset = getCachedSynset(key);
       if (synset == null) {
           try {
               if (line == null) {
                   line = getFileManager().readLineAt(pos, DictionaryFileType.DATA, offset);
               }
               synset = _factory.createSynset(pos, line);
               synset.getWords();
               
               if (synset != null) {
                   cacheSynset(key, synset);
               }
           } catch (IOException e) {
               throw new JWNLException("DICTIONARY_EXCEPTION_005", new Long(offset), e);
           }
       }
	return synset;
}
 
开发者ID:FabianFriedrich,项目名称:Text2Process,代码行数:21,代码来源:FileBackedDictionary.java

示例10: JWNLLemmatizer

import net.didion.jwnl.JWNLException; //导入依赖的package包/类
/**
 * Creates JWNL dictionary and morphological processor objects in
 * JWNLemmatizer constructor. It also loads the JWNL configuration into the
 * constructor. 
 * 
 * Constructor code based on Apache OpenNLP JWNLDictionary class. 
 * 
 * @param wnDirectory
 * @throws IOException
 * @throws JWNLException
 */
public JWNLLemmatizer(String wnDirectory) throws IOException, JWNLException {
  PointerType.initialize();
  Adjective.initialize();
  VerbFrame.initialize();
  Map<POS, String[][]> suffixMap = new HashMap<POS, String[][]>();
  suffixMap.put(POS.NOUN, new String[][] { { "s", "" }, { "ses", "s" },
      { "xes", "x" }, { "zes", "z" }, { "ches", "ch" }, { "shes", "sh" },
      { "men", "man" }, { "ies", "y" } });
  suffixMap.put(POS.VERB, new String[][] { { "s", "" }, { "ies", "y" },
      { "es", "e" }, { "es", "" }, { "ed", "e" }, { "ed", "" },
      { "ing", "e" }, { "ing", "" } });
  suffixMap.put(POS.ADJECTIVE, new String[][] { { "er", "" }, { "est", "" },
      { "er", "e" }, { "est", "e" } });
  DetachSuffixesOperation tokDso = new DetachSuffixesOperation(suffixMap);
  tokDso.addDelegate(DetachSuffixesOperation.OPERATIONS, new Operation[] {
      new LookupIndexWordOperation(), new LookupExceptionsOperation() });
  TokenizerOperation tokOp = new TokenizerOperation(new String[] { " ", "-" });
  tokOp.addDelegate(TokenizerOperation.TOKEN_OPERATIONS,
      new Operation[] { new LookupIndexWordOperation(),
          new LookupExceptionsOperation(), tokDso });
  DetachSuffixesOperation morphDso = new DetachSuffixesOperation(suffixMap);
  morphDso.addDelegate(DetachSuffixesOperation.OPERATIONS, new Operation[] {
      new LookupIndexWordOperation(), new LookupExceptionsOperation() });
  Operation[] operations = { new LookupExceptionsOperation(), morphDso, tokOp };
  morphy = new DefaultMorphologicalProcessor(operations);
  FileManager manager = new FileManagerImpl(wnDirectory,
      PrincetonRandomAccessDictionaryFile.class);
  FileDictionaryElementFactory factory = new PrincetonWN17FileDictionaryElementFactory();
  FileBackedDictionary.install(manager, morphy, factory, true);
  dict = net.didion.jwnl.dictionary.Dictionary.getInstance();
  morphy = dict.getMorphologicalProcessor();
}
 
开发者ID:apache,项目名称:opennlp-addons,代码行数:44,代码来源:JWNLLemmatizer.java

示例11: lemmatize

import net.didion.jwnl.JWNLException; //导入依赖的package包/类
/**
 * It takes a word and a POS tag and obtains a word's lemma from WordNet.
 * 
 * @param word
 * @param postag
 * @return lemma
 */
public String lemmatize(String word, String postag) {
  String constantTag = "NNP";
  IndexWord baseForm;
  String lemma = null;
  try {
    POS pos;
    if (postag.startsWith("N") || postag.startsWith("n")) {
      pos = POS.NOUN;
    } else if (postag.startsWith("V") || postag.startsWith("v")) {
      pos = POS.VERB;
    } else if (postag.startsWith("J") || postag.startsWith("a")) {
      pos = POS.ADJECTIVE;
    } else if (postag.startsWith("RB") || postag.startsWith("r")) {
      pos = POS.ADVERB;
    } else {
      pos = POS.ADVERB;
    }
    baseForm = morphy.lookupBaseForm(pos, word);
    if (baseForm != null) {
      lemma = baseForm.getLemma().toString();
    }
    else if (baseForm == null && postag.startsWith(String.valueOf(constantTag))) {
        lemma = word;
      }
      else {
        lemma= word.toLowerCase();
      }
  } catch (JWNLException e) {
    e.printStackTrace();
    return null;
  }
  return lemma;
}
 
开发者ID:apache,项目名称:opennlp-addons,代码行数:41,代码来源:JWNLLemmatizer.java

示例12: getBaseForm

import net.didion.jwnl.JWNLException; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private String getBaseForm(String word, POS POS) throws JWNLException {

	String lemma, l;
	List<String> indexWords;
	int lemmas;

	lemma = word;
	indexWords = mDictionary.getMorphologicalProcessor().lookupAllBaseForms(POS, word);
	lemmas = indexWords.size();

	if (lemmas > 0) {

		lemma = indexWords.get(0);

		for (int i = 1; i < lemmas; i++) {

			l = indexWords.get(i);

			if (l.equals(word)) {
				lemma = l;
				break;
			}
		}
	}

	return lemma;
}
 
开发者ID:SI3P,项目名称:supWSD,代码行数:29,代码来源:SensEvalMNS.java

示例13: getAttributeSenses

import net.didion.jwnl.JWNLException; //导入依赖的package包/类
List<Synset> getAttributeSenses(Synset sense) throws JWNLException {
    Pointer[] pointers = sense.getPointers(PointerType.ATTRIBUTE);
    List<Synset> attrsenses = new ArrayList<Synset>();
   for (Pointer p:pointers) {
        Synset attrSS = p.getTargetSynset();
        attrsenses.add(attrSS);
    }
    return attrsenses;
}
 
开发者ID:sasinda,项目名称:OntologyBasedInormationExtractor,代码行数:10,代码来源:LinguisticEnhancer.java

示例14: Examples

import net.didion.jwnl.JWNLException; //导入依赖的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

示例15: go

import net.didion.jwnl.JWNLException; //导入依赖的package包/类
public void go() throws JWNLException {
	demonstrateMorphologicalAnalysis(MORPH_PHRASE);
	demonstrateListOperation(ACCOMPLISH);
	demonstrateTreeOperation(DOG);
	demonstrateAsymmetricRelationshipOperation(DOG, CAT);
	demonstrateSymmetricRelationshipOperation(FUNNY, DROLL);
}
 
开发者ID:kostagiolasn,项目名称:NucleosomePatternClassifier,代码行数:8,代码来源:Examples.java


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