SenseGenerator { public List<Sense> generateSenses(Set<LexUnit> luGroup){ List<Sense> senses = new ArrayList<Sense>(); for(LexUnit lu : luGroup){ Sense sense = synsetGenerator.getSense(lu); luSenseMappings.put(lu, sense); sense.setIndex(lu.getSense()); de.tudarmstadt.ukp.lmf.model.semantics.Synset lmfSynset = synsetGenerator.getLMFSynset(lu); sense.setSynset(lmfSynset); List<SemanticLabel> semanticLabels = new LinkedList<SemanticLabel>(); SemanticLabel semanticLabel = new SemanticLabel(); semanticLabels.add(semanticLabel); semanticLabel.setLabel(semanticClassLabelExtractor.getLUSemanticClassLabel(lu)); semanticLabel.setType(ELabelTypeSemantics.semanticField); if(lu.isArtificial()){ SemanticLabel semanticLabelArt = new SemanticLabel(); semanticLabelArt.setLabel("artificialConcept"); semanticLabelArt.setType(ELabelTypeSemantics.resourceSpecific); semanticLabels.add(semanticLabelArt); } sense.setSemanticLabels(semanticLabels); List<SenseExample> senseExamples = senseExampleGenerator.generateSenseExamples(lu); sense.setSenseExamples(senseExamples); List<WiktionaryParaphrase> paraphraseList = lu.getWiktionaryParaphrases(); List<Definition> definitions = new LinkedList<Definition>(); for (WiktionaryParaphrase paraphrase : paraphraseList) { String[] paraphraseString = paraphrase.toString().split("Wiktionary sense definition:"); String writtenText = paraphraseString[1].replaceAll(", edited:.*", ""); if (writtenText != null && !writtenText.equals("") && !writtenText.equals(" ")) { Definition definition = new Definition(); List<TextRepresentation> textRepresentations = new LinkedList<TextRepresentation>(); TextRepresentation textRepresentation = new TextRepresentation(); textRepresentation.setLanguageIdentifier(ELanguageIdentifier.GERMAN); textRepresentation.setWrittenText(writtenText); textRepresentations.add(textRepresentation); definition.setTextRepresentations(textRepresentations); definitions.add(definition); } } sense.setDefinitions(definitions); MonolingualExternalRef mer = new MonolingualExternalRef(); mer.setExternalReference(Integer.toString(lu.getId())); mer.setExternalSystem(resourceVersion + "_" + LEXICAL_UNIT); LinkedList<MonolingualExternalRef> mers = new LinkedList<MonolingualExternalRef>(); mers.add(mer); sense.setMonolingualExternalRefs(mers); senses.add(sense); setSenseRelations(lu); } return senses; } SenseGenerator(GermaNet gnet, String resourceVersion); List<Sense> generateSenses(Set<LexUnit> luGroup); SynsetGenerator getSynsetGenerator(); Sense getSense(LexUnit lu); final static String LEXICAL_UNIT; }
@Test public void testGenerateSenses(){ Set<LexUnit> luGroup = new HashSet<LexUnit>(4); luGroup.add(gnet.getLexUnitByID(84356)); luGroup.add(gnet.getLexUnitByID(85423)); luGroup.add(gnet.getLexUnitByID(79989)); luGroup.add(gnet.getLexUnitByID(84884)); List<Sense> senses = senseGenerator.generateSenses(luGroup); assertEquals(senses.size(), luGroup.size()); for(Sense sense : senses){ List<MonolingualExternalRef> monolingualExternalRefs = sense.getMonolingualExternalRefs(); assertFalse(monolingualExternalRefs.isEmpty()); for(MonolingualExternalRef monolingualExternalRef : monolingualExternalRefs){ assertFalse(monolingualExternalRef == null); String externalSystem = monolingualExternalRef.getExternalSystem(); assertNotNull(externalSystem); assertEquals(externalSystem, "GermaNet 7.0 LexicalUnit-ID"); String externalReference = monolingualExternalRef.getExternalReference(); assertNotNull(externalReference); assertFalse(externalReference.equals("")); assertFalse(externalReference.equals(" ")); } } }