use of org.apache.clerezza.commons.rdf.impl.utils.TripleImpl in project stanbol by apache.
the class TestEntityLinkingEnhancementEngine method initContentItem.
/**
* Creates and initialises a new content item using {@link #CONTEXT} as
* content and
* @return
* @throws IOException
*/
private ContentItem initContentItem() throws IOException {
ContentItem ci = ciFactory.createContentItem(new IRI("urn:iks-project:enhancer:text:content-item:person"), new StringSource(CONTEXT));
//add three text annotations to be consumed by this test
getTextAnnotation(ci, PERSON, CONTEXT, DBPEDIA_PERSON);
getTextAnnotation(ci, ORGANISATION, CONTEXT, DBPEDIA_ORGANISATION);
getTextAnnotation(ci, PLACE, CONTEXT, DBPEDIA_PLACE);
//add the language
ci.getMetadata().add(new TripleImpl(ci.getUri(), Properties.DC_LANGUAGE, new PlainLiteralImpl("en")));
return ci;
}
use of org.apache.clerezza.commons.rdf.impl.utils.TripleImpl in project stanbol by apache.
the class EntityCoReferenceEngineTest method testSpatialCoref.
@Test
public void testSpatialCoref() throws EngineException, IOException {
ContentItem ci = ciFactory.createContentItem(new StringSource(SPATIAL_TEXT));
Graph graph = ci.getMetadata();
IRI textEnhancement = EnhancementEngineHelper.createTextEnhancement(ci, engine);
graph.add(new TripleImpl(textEnhancement, DC_LANGUAGE, new PlainLiteralImpl("en")));
graph.add(new TripleImpl(textEnhancement, ENHANCER_CONFIDENCE, new PlainLiteralImpl("100.0")));
graph.add(new TripleImpl(textEnhancement, DC_TYPE, DCTERMS_LINGUISTIC_SYSTEM));
Entry<IRI, Blob> textBlob = ContentItemHelper.getBlob(ci, Collections.singleton("text/plain"));
AnalysedText at = atFactory.createAnalysedText(ci, textBlob.getValue());
Sentence sentence1 = at.addSentence(0, SPATIAL_SENTENCE_1.indexOf(".") + 1);
Chunk angelaMerkel = sentence1.addChunk(0, "Angela Merkel".length());
angelaMerkel.addAnnotation(NlpAnnotations.NER_ANNOTATION, Value.value(new NerTag("Angela Merkel", OntologicalClasses.DBPEDIA_PERSON)));
Sentence sentence2 = at.addSentence(SPATIAL_SENTENCE_1.indexOf(".") + 1, SPATIAL_SENTENCE_1.length() + SPATIAL_SENTENCE_2.indexOf(".") + 1);
int theStartIdx = sentence2.getSpan().indexOf("The");
int germanStartIdx = sentence2.getSpan().indexOf("German");
int chancellorStartIdx = sentence2.getSpan().indexOf("politician");
Token the = sentence2.addToken(theStartIdx, theStartIdx + "The".length());
the.addAnnotation(NlpAnnotations.POS_ANNOTATION, Value.value(new PosTag("The", LexicalCategory.PronounOrDeterminer, Pos.Determiner)));
Token german = sentence2.addToken(germanStartIdx, germanStartIdx + "German".length());
german.addAnnotation(NlpAnnotations.POS_ANNOTATION, Value.value(new PosTag("German", LexicalCategory.Adjective)));
Token politician = sentence2.addToken(chancellorStartIdx, chancellorStartIdx + "politician".length());
politician.addAnnotation(NlpAnnotations.POS_ANNOTATION, Value.value(new PosTag("politician", LexicalCategory.Noun)));
Chunk theGermanChancellor = sentence2.addChunk(theStartIdx, chancellorStartIdx + "politician".length());
theGermanChancellor.addAnnotation(NlpAnnotations.PHRASE_ANNOTATION, Value.value(new PhraseTag("The German politician", LexicalCategory.Noun)));
engine.computeEnhancements(ci);
Value<CorefFeature> representativeCorefValue = angelaMerkel.getAnnotation(NlpAnnotations.COREF_ANNOTATION);
Assert.assertNotNull(representativeCorefValue);
CorefFeature representativeCoref = representativeCorefValue.value();
Assert.assertTrue(representativeCoref.isRepresentative());
Assert.assertTrue(representativeCoref.getMentions().contains(theGermanChancellor));
Value<CorefFeature> subordinateCorefValue = theGermanChancellor.getAnnotation(NlpAnnotations.COREF_ANNOTATION);
Assert.assertNotNull(subordinateCorefValue);
CorefFeature subordinateCoref = subordinateCorefValue.value();
Assert.assertTrue(!subordinateCoref.isRepresentative());
Assert.assertTrue(subordinateCoref.getMentions().contains(angelaMerkel));
}
use of org.apache.clerezza.commons.rdf.impl.utils.TripleImpl in project stanbol by apache.
the class TestOntologyNetworkPersistence method updatesGraphOnSpaceModification.
@Test
public void updatesGraphOnSpaceModification() throws Exception {
// Ensure the metadata graph is there.
Graph meta = ontologyProvider.getMetaGraph(Graph.class);
assertNotNull(meta);
String scopeId = "updateTest";
Scope scope = onm.createOntologyScope(scopeId, new GraphContentInputSource(getClass().getResourceAsStream("/ontologies/test1.owl")));
IRI collector = new IRI(_NS_STANBOL_INTERNAL + OntologySpace.shortName + "/" + scope.getCoreSpace().getID());
// Has no versionIRI
IRI test1id = new IRI("http://stanbol.apache.org/ontologies/test1.owl");
// Be strict: the whole property pair must be there.
IRI predicate = MANAGES_URIREF;
assertTrue(meta.contains(new TripleImpl(collector, predicate, test1id)));
predicate = IS_MANAGED_BY_URIREF;
assertTrue(meta.contains(new TripleImpl(test1id, predicate, collector)));
// To modify the core space.
scope.tearDown();
scope.getCoreSpace().addOntology(new GraphContentInputSource(getClass().getResourceAsStream("/ontologies/minorcharacters.owl")));
IRI minorId = new IRI("http://stanbol.apache.org/ontologies/pcomics/minorcharacters.owl");
predicate = MANAGES_URIREF;
assertTrue(meta.contains(new TripleImpl(collector, predicate, minorId)));
predicate = IS_MANAGED_BY_URIREF;
assertTrue(meta.contains(new TripleImpl(minorId, predicate, collector)));
scope.getCustomSpace().addOntology(new GraphContentInputSource(getClass().getResourceAsStream("/ontologies/test1.owl")));
scope.getCustomSpace().addOntology(new GraphContentInputSource(getClass().getResourceAsStream("/ontologies/minorcharacters.owl")));
}
use of org.apache.clerezza.commons.rdf.impl.utils.TripleImpl in project stanbol by apache.
the class ConstantMapping method apply.
@Override
public boolean apply(Graph graph, BlankNodeOrIRI subject, Metadata metadata) {
for (RDFTerm value : values) {
graph.add(new TripleImpl(subject, ontProperty, value));
mappingLogger.log(subject, ontProperty, null, value);
}
return true;
}
use of org.apache.clerezza.commons.rdf.impl.utils.TripleImpl in project stanbol by apache.
the class ResourceMapping method apply.
@Override
public boolean apply(Graph graph, BlankNodeOrIRI subject, Metadata metadata) {
boolean added = false;
BlankNodeOrIRI s = new BlankNode();
mappingLogger.log(subject, ontProperty, null, s);
if (!required.isEmpty()) {
Graph g = new SimpleGraph();
for (Mapping m : required) {
if (!m.apply(g, s, metadata)) {
return false;
}
}
graph.addAll(g);
added = true;
}
for (Mapping m : optional) {
if (m.apply(graph, s, metadata)) {
added = true;
}
}
if (added) {
for (Mapping m : additional) {
m.apply(graph, s, metadata);
}
graph.add(new TripleImpl(subject, ontProperty, s));
}
return added;
}
Aggregations