use of org.apache.clerezza.commons.rdf.impl.utils.PlainLiteralImpl in project stanbol by apache.
the class DBPSpotlightDisambiguateEnhancementEngine method createEnhancements.
/**
* The method adds the returned DBpedia Spotlight annotations to the content
* item's metadata. For each DBpedia resource an EntityAnnotation is created
* and linked to the according TextAnnotation.
*
* @param occs
* a Collection of entity information
* @param ci
* the content item
*/
public void createEnhancements(Collection<Annotation> occs, ContentItem ci, Language language) {
HashMap<RDFTerm, IRI> entityAnnotationMap = new HashMap<RDFTerm, IRI>();
for (Annotation occ : occs) {
if (textAnnotationsMap.get(occ.surfaceForm) != null) {
IRI textAnnotation = textAnnotationsMap.get(occ.surfaceForm);
Graph model = ci.getMetadata();
IRI entityAnnotation = EnhancementEngineHelper.createEntityEnhancement(ci, this);
entityAnnotationMap.put(occ.uri, entityAnnotation);
Literal label = new PlainLiteralImpl(occ.surfaceForm.name, language);
model.add(new TripleImpl(entityAnnotation, DC_RELATION, textAnnotation));
model.add(new TripleImpl(entityAnnotation, ENHANCER_ENTITY_LABEL, label));
Collection<String> t = occ.getTypeNames();
if (t != null) {
Iterator<String> it = t.iterator();
while (it.hasNext()) model.add(new TripleImpl(entityAnnotation, ENHANCER_ENTITY_TYPE, new IRI(it.next())));
}
model.add(new TripleImpl(entityAnnotation, ENHANCER_ENTITY_REFERENCE, occ.uri));
}
}
}
use of org.apache.clerezza.commons.rdf.impl.utils.PlainLiteralImpl in project stanbol by apache.
the class LocationEnhancementEngine method writeEntityEnhancement.
/**
* Writes an entity enhancement for the content item in the parsed graph
* based on the parsed toponym.
*
* @param contentItemId The id of the contentItem
* @param graph The graph used to write the triples
* @param literalFactory the literal factory used to create literals
* @param toponym the toponym
* @param relatedEnhancements related enhancements
* @param requiresEnhancements required enhancements
* @param defaultScore the score used as default id not present. This is
* used to parse the score of the Toponym if this method is used to add a
* parent Toponym.
*
* @return The IRI of the created entity enhancement
*/
private IRI writeEntityEnhancement(IRI contentItemId, Graph graph, LiteralFactory literalFactory, Toponym toponym, Collection<BlankNodeOrIRI> relatedEnhancements, Collection<BlankNodeOrIRI> requiresEnhancements, Double score) {
IRI entityRef = new IRI("http://sws.geonames.org/" + toponym.getGeoNameId() + '/');
FeatureClass featureClass = toponym.getFeatureClass();
log.debug(" > featureClass " + featureClass);
IRI entityAnnotation = EnhancementEngineHelper.createEntityEnhancement(graph, this, contentItemId);
// first relate this entity annotation to the text annotation(s)
if (relatedEnhancements != null) {
for (BlankNodeOrIRI related : relatedEnhancements) {
graph.add(new TripleImpl(entityAnnotation, DC_RELATION, related));
}
}
if (requiresEnhancements != null) {
for (BlankNodeOrIRI requires : requiresEnhancements) {
graph.add(new TripleImpl(entityAnnotation, DC_REQUIRES, requires));
//STANBOL-767: also add dc:relation link
graph.add(new TripleImpl(entityAnnotation, DC_RELATION, requires));
}
}
graph.add(new TripleImpl(entityAnnotation, ENHANCER_ENTITY_REFERENCE, entityRef));
log.debug(" > name " + toponym.getName());
graph.add(new TripleImpl(entityAnnotation, ENHANCER_ENTITY_LABEL, new PlainLiteralImpl(toponym.getName())));
if (score != null) {
graph.add(new TripleImpl(entityAnnotation, ENHANCER_CONFIDENCE, literalFactory.createTypedLiteral(score)));
}
//now get all the entity types for the results
Set<IRI> entityTypes = new HashSet<IRI>();
//first based on the feature class
Collection<IRI> featureClassTypes = FEATURE_CLASS_CONCEPT_MAPPINGS.get(featureClass);
if (featureClassTypes != null) {
entityTypes.addAll(featureClassTypes);
}
//second for the feature Code
String featureCode = toponym.getFeatureCode();
Collection<IRI> featureCodeTypes = FEATURE_TYPE_CONCEPT_MAPPINGS.get(featureCode);
if (featureCodeTypes != null) {
entityTypes.addAll(featureCodeTypes);
}
//third add the feature Code as additional type
entityTypes.add(new IRI(NamespaceEnum.geonames + featureClass.name() + '.' + featureCode));
//finally add the type triples to the enhancement
for (IRI entityType : entityTypes) {
graph.add(new TripleImpl(entityAnnotation, ENHANCER_ENTITY_TYPE, entityType));
}
return entityAnnotation;
}
use of org.apache.clerezza.commons.rdf.impl.utils.PlainLiteralImpl in project stanbol by apache.
the class EnhancerUtils method addActiveEngines.
/**
* Create the RDF data for the currently active EnhancementEngines.<p>
* Note the the parsed rootUrl MUST already consider offsets configured
* for the Stanbol RESTful service. When called from within a
* {@link BaseStanbolResource} the following code segment should be used:<p>
* <code><pre>
* String rootUrl = uriInfo.getBaseUriBuilder().path(getRootUrl()).build().toString();
* </pre></code>
* @param activeEngines the active enhancement engines as {@link Entry entries}.
* @param graph the RDF graph to add the triples
* @param rootUrl the root URL used by the current request
* @see EnhancerUtils#buildEnginesMap(EnhancementEngineManager)
*/
public static void addActiveEngines(Iterable<Entry<ServiceReference, EnhancementEngine>> activeEngines, Graph graph, String rootUrl) {
IRI enhancerResource = new IRI(rootUrl + "enhancer");
graph.add(new TripleImpl(enhancerResource, RDF.type, Enhancer.ENHANCER));
for (Entry<ServiceReference, EnhancementEngine> entry : activeEngines) {
IRI engineResource = new IRI(rootUrl + "enhancer/engine/" + entry.getValue().getName());
graph.add(new TripleImpl(enhancerResource, Enhancer.HAS_ENGINE, engineResource));
graph.add(new TripleImpl(engineResource, RDF.type, ENHANCEMENT_ENGINE));
graph.add(new TripleImpl(engineResource, RDFS.label, new PlainLiteralImpl(entry.getValue().getName())));
}
}
use of org.apache.clerezza.commons.rdf.impl.utils.PlainLiteralImpl in project stanbol by apache.
the class EnhancerUtils method addActiveChains.
/**
* Create the RDF data for the currently active Enhancement {@link Chain}s.<p>
* Note the the parsed rootUrl MUST already consider offsets configured
* for the Stanbol RESTful service. When called from within a
* {@link BaseStanbolResource} the following code segment should be used:<p>
* <code><pre>
* String rootUrl = uriInfo.getBaseUriBuilder().path(getRootUrl()).build().toString();
* </pre></code>
* @param activeChains the active enhancement chains as {@link Entry entries}.
* @param defaultChain the default chain
* @param graph the RDF graph to add the triples
* @param rootUrl the root URL used by the current request
*/
public static void addActiveChains(Iterable<Entry<ServiceReference, Chain>> activeChains, Chain defaultChain, Graph graph, String rootUrl) {
IRI enhancer = new IRI(rootUrl + "enhancer");
graph.add(new TripleImpl(enhancer, RDF.type, Enhancer.ENHANCER));
for (Entry<ServiceReference, Chain> entry : activeChains) {
IRI chainResource = new IRI(rootUrl + "enhancer/chain/" + entry.getValue().getName());
graph.add(new TripleImpl(enhancer, Enhancer.HAS_CHAIN, chainResource));
if (entry.getValue().equals(defaultChain)) {
graph.add(new TripleImpl(enhancer, Enhancer.HAS_DEFAULT_CHAIN, chainResource));
}
graph.add(new TripleImpl(chainResource, RDF.type, Enhancer.ENHANCEMENT_CHAIN));
graph.add(new TripleImpl(chainResource, RDFS.label, new PlainLiteralImpl(entry.getValue().getName())));
}
}
use of org.apache.clerezza.commons.rdf.impl.utils.PlainLiteralImpl in project stanbol by apache.
the class ContentItemReader method createParsedLanguageAnnotation.
/**
* Creates a fise:TextAnnotation for the explicitly parsed Content-Language
* header. The confidence of this annotation is set <code>1.0</code> (see
* <a href="https://issues.apache.org/jira/browse/STANBOL-1417">STANBOL-1417</a>).
* @param ci the {@link ContentItem} to the the language annotation
* @param lang the parsed language
*/
private void createParsedLanguageAnnotation(ContentItem ci, String lang) {
Graph m = ci.getMetadata();
IRI la = new IRI("urn:enhancement-" + EnhancementEngineHelper.randomUUID());
//add the fise:Enhancement information
m.add(new TripleImpl(la, RDF_TYPE, ENHANCER_ENHANCEMENT));
m.add(new TripleImpl(la, RDF_TYPE, ENHANCER_TEXTANNOTATION));
m.add(new TripleImpl(la, ENHANCER_EXTRACTED_FROM, ci.getUri()));
m.add(new TripleImpl(la, DC_CREATED, lf.createTypedLiteral(new Date())));
m.add(new TripleImpl(la, DC_CREATOR, lf.createTypedLiteral("Content-Language Header of the request")));
//add fise:TextAnnotation information as expected by a Language annotation.
m.add(new TripleImpl(la, DC_TYPE, DCTERMS_LINGUISTIC_SYSTEM));
m.add(new TripleImpl(la, DC_LANGUAGE, new PlainLiteralImpl(lang)));
//we set the confidence to 1.0^^xsd:double
m.add(new TripleImpl(la, ENHANCER_CONFIDENCE, lf.createTypedLiteral(Double.valueOf(1.0f))));
}
Aggregations