SenseGenerator { public List<Sense> generateSenses(Set<Word> lexemeGroup, LexicalEntry lexicalEntry){ List<Sense> result = new ArrayList<Sense>(); List<Sense> needDummySenseNumber = new ArrayList<Sense>(); int nextIndex = 1; for(Word lexeme : lexemeGroup){ Sense sense = new Sense(); lexemeSenseMappings.put(lexeme, sense); sense.setId(getNewID()); sense.setLexicalEntry(lexicalEntry); String senseNumber; try { senseNumber = isr.getSenseNumber(lexeme.getSenseKey()); } catch (JWNLException e) { throw new IllegalArgumentException(e); } if(senseNumber != null){ int index = Integer.parseInt(senseNumber); if(nextIndex <= index) { nextIndex = index+1; } sense.setIndex(index); } else{ needDummySenseNumber.add(sense); StringBuffer sb = new StringBuffer(128); sb.append("IndexSenseReader did not provide sense number for senseKey "); try { sb.append(lexeme.getSenseKey()).append('\n'); } catch (JWNLException e) { throw new IllegalArgumentException(e); } sb.append("adding a dummy value of sense number"); logger.warn(sb.toString()); } net.sf.extjwnl.data.Synset lexemeSynset = lexeme.getSynset(); Synset lmfSynset = synsetGenerator.getLMFSynset(lexemeSynset); if(lmfSynset == null){ StringBuffer sb = new StringBuffer(512); sb.append("Synset generator did not provide Uby-LMF Synset for WordNet's Synset "); sb.append(lexemeSynset).append('\n'); sb.append("Closing VM"); logger.error(sb.toString()); System.exit(1); } sense.setSynset(lmfSynset); List<SemanticLabel> semanticLabels = new LinkedList<SemanticLabel>(); SemanticLabel semanticLabel = new SemanticLabel(); semanticLabels.add(semanticLabel); semanticLabel.setLabel(lexemeSynset.getLexFileName()); semanticLabel.setType(ELabelTypeSemantics.semanticField); sense.setSemanticLabels(semanticLabels); MonolingualExternalRef monolingualExternalRef = new MonolingualExternalRef(); StringBuffer sb = new StringBuffer(32); sb.append(lexeme.getSynset().getPOS()); sb.append(" "); try { sb.append(lexeme.getSenseKey()); } catch (JWNLException e) { throw new IllegalArgumentException(e); } monolingualExternalRef.setExternalSystem("WordNet 3.0 part of speech and sense key"); monolingualExternalRef.setExternalReference(sb.toString()); List<MonolingualExternalRef> monolingualExternalRefs = new LinkedList<MonolingualExternalRef>(); monolingualExternalRefs.add(monolingualExternalRef); sense.setMonolingualExternalRefs(monolingualExternalRefs); / for(Sense sense : needDummySenseNumber) { sense.setIndex(nextIndex++); } return result; } SenseGenerator(SynsetGenerator synsetGenerator, IndexSenseReader isr, String resourceVersion); List<Sense> generateSenses(Set<Word> lexemeGroup, LexicalEntry lexicalEntry); Sense getSense(Word lexeme); Set<Word> getProcessedLexemes(); final static String EXTERNAL_SYSTEM_SENSE_KEY; }
@Test public final void testGenerateSensesSetOfWordLexicalEntry() throws JWNLException { SynsetGenerator synsetGenerator = new SynsetGenerator(wordNet, "WordNet_3.0_eng"); synsetGenerator.initialize(); String UBY_HOME = System.getenv("UBY_HOME"); IndexSenseReader isr = new IndexSenseReader(); isr.initialize(new File(UBY_HOME+"/WordNet/wordnet3/dict/index.sense")); SenseGenerator senseGenerator = new SenseGenerator(synsetGenerator, isr,"WordNet_3.0_eng"); String lexicalEntryId = "testLexicalEntry"; LexicalEntry lexicalEntry = new LexicalEntry(lexicalEntryId); Set<Word> lexemeGroup = new HashSet<Word>(); lexemeGroup.add(wordNet.getWordBySenseKey("polemics%1:09:00::")); List<Sense> senses = senseGenerator.generateSenses(lexemeGroup, lexicalEntry); for(Sense sense : senses) { assertEquals(lexicalEntry, sense.getLexicalEntry()); } }