/** * Parse a dependency tree from generated objects TODO: There are NIF properties missing to * describe dependency relations from phrases to other phrases TODO: What exactly is the "root" * node? I will make this the sentence resource but that seems to be wrong. should there be an * artificial "root" phrase? what does it contain? what offsets does it have? * * @param sentenceObjects */ private void parseDependencyTree( List<ConLLWord> sentenceObjects, OntModel inputModel, Individual sentence, Individual context) { // create the tree // TODO: defining new property here, should be changed to work ootb ObjectProperty phraseHead = inputModel.createObjectProperty( "http://persistence.uni-leipzig.org/nlp2rdf/ontologies/nif-core#phraseHead"); phraseHead.addProperty(RDFS.comment, "The head of a Phrase."); phraseHead.addProperty(RDFS.domain, NIFOntClasses.Phrase.getUri()); phraseHead.addProperty(RDFS.range, NIFOntClasses.Phrase.getUri()); ObjectProperty depRelType = inputModel.createObjectProperty( "http://persistence.uni-leipzig.org/nlp2rdf/ontologies/nif-core#dependencyRelationType"); depRelType.addProperty( RDFS.comment, "Dependency relation to the HEAD. The set of dependency relations depends on the particular language. Note that depending on the original treebank annotation, the dependency relation may be meaningful or simply 'ROOT'. "); depRelType.addProperty(RDFS.domain, NIFOntClasses.Phrase.getUri()); ObjectProperty govTODep = NIFObjectProperties.dependency.getObjectProperty(inputModel); for (ConLLWord word : sentenceObjects) { int phraseHeadId = word.getPhraseHeadId(); Individual wordResource = word.getResource(); // every word is a phrase wordResource.addOntClass(NIFOntClasses.Phrase.getOntClass(inputModel)); if (phraseHeadId == 0) { // root node, making the sentence the head wordResource.addProperty(depRelType, word.getPhraseType()); } else { // ids start with 1, List<> indexes starts with 0 ConLLWord phraseHeadObject = sentenceObjects.get(phraseHeadId - 1); phraseHeadObject.getResource().addProperty(govTODep, wordResource); wordResource.addProperty(phraseHead, phraseHeadObject.getResource()); wordResource.addProperty( NIFDatatypeProperties.head.getDatatypeProperty(inputModel), String.valueOf(phraseHeadId)); wordResource.addProperty(depRelType, word.getPhraseType()); } } }