Search in sources :

Example 1 with CandidateResource

use of org.apache.stanbol.enhancer.engines.dbpspotlight.model.CandidateResource in project stanbol by apache.

the class DBPSpotlightCandidatesEnhancementEngine method createEnhancements.

/**
	 * This generates enhancement structures for the entities from DBPedia
	 * Spotlight and adds them to the content item's metadata. For each surface
	 * form a TextAnnotation and the according EntityAnnotations are created.
	 * 
	 * @param occs
	 *            a Collection of entity information
	 * @param ci
	 *            the content item
	 */
protected void createEnhancements(Collection<SurfaceForm> occs, ContentItem ci, String text, Language language) {
    // TODO create TextEnhancement (form, start, end, type?)
    HashMap<String, IRI> entityAnnotationMap = new HashMap<String, IRI>();
    Graph model = ci.getMetadata();
    for (SurfaceForm occ : occs) {
        IRI textAnnotation = SpotlightEngineUtils.createTextEnhancement(occ, this, ci, text, language);
        Iterator<CandidateResource> resources = occ.resources.iterator();
        while (resources.hasNext()) {
            CandidateResource resource = resources.next();
            IRI entityAnnotation = SpotlightEngineUtils.createEntityAnnotation(resource, this, ci, textAnnotation);
            entityAnnotationMap.put(resource.localName, entityAnnotation);
        }
        if (entityAnnotationMap.containsKey(occ.name)) {
            model.add(new TripleImpl(entityAnnotationMap.get(occ.name), DC_RELATION, textAnnotation));
        } else {
            entityAnnotationMap.put(occ.name, textAnnotation);
        }
    }
}
Also used : IRI(org.apache.clerezza.commons.rdf.IRI) Graph(org.apache.clerezza.commons.rdf.Graph) HashMap(java.util.HashMap) SurfaceForm(org.apache.stanbol.enhancer.engines.dbpspotlight.model.SurfaceForm) CandidateResource(org.apache.stanbol.enhancer.engines.dbpspotlight.model.CandidateResource) TripleImpl(org.apache.clerezza.commons.rdf.impl.utils.TripleImpl)

Aggregations

HashMap (java.util.HashMap)1 Graph (org.apache.clerezza.commons.rdf.Graph)1 IRI (org.apache.clerezza.commons.rdf.IRI)1 TripleImpl (org.apache.clerezza.commons.rdf.impl.utils.TripleImpl)1 CandidateResource (org.apache.stanbol.enhancer.engines.dbpspotlight.model.CandidateResource)1 SurfaceForm (org.apache.stanbol.enhancer.engines.dbpspotlight.model.SurfaceForm)1