Search in sources :

Example 6 with RdfRepresentation

use of org.apache.stanbol.entityhub.model.clerezza.RdfRepresentation in project stanbol by apache.

the class TrackingDereferencerBase method copyMapped.

/**
     * Applies the field mappings to the representation and stores the results
     * in the graph
     * @param uri the uri of the entity to dereference
     * @param rep the data for the entity as in the entityhub
     * @param fieldMapper the {@link FieldMapper} parsed from the dereference context
     * @param langs the set of languages to dereference
     * @param graph the graph to store the mapping results
     * @param writeLock the write lock for the graph
     */
private void copyMapped(IRI uri, Representation rep, FieldMapper fieldMapper, Set<String> langs, Graph graph, Lock writeLock) {
    //NOTE: The fieldMapper parsed via the context does already have a
    //      filter for the parsed languages. Because of that the old code
    //      adding such a language filter is no longer needed
    //        FieldMapper fieldMapper;
    //        if(!langs.isEmpty()){ //if we need to filter for specific languages
    //            fieldMapper = this.fieldMapper != null ? this.fieldMapper.clone() :
    //                new DefaultFieldMapperImpl(ValueConverterFactory.getDefaultInstance());
    //            fieldMapper.addMapping(new FieldMapping(new TextConstraint(
    //                (String)null, langs.toArray(new String[langs.size()]))));
    //        } else { //just use the fieldMapper as parsed in the config
    //            fieldMapper = this.fieldMapper;
    //        }
    //execute the field mappings
    writeLock.lock();
    try {
        RdfRepresentation clerezzaRep = valueFactory.createRdfRepresentation(uri, graph);
        fieldMapper.applyMappings(rep, clerezzaRep, valueFactory);
        if (log.isTraceEnabled()) {
            log.trace("dereferenced via Mappings {}", ModelUtils.getRepresentationInfo(clerezzaRep));
        }
    } finally {
        writeLock.unlock();
    }
}
Also used : RdfRepresentation(org.apache.stanbol.entityhub.model.clerezza.RdfRepresentation)

Example 7 with RdfRepresentation

use of org.apache.stanbol.entityhub.model.clerezza.RdfRepresentation in project stanbol by apache.

the class RefactorEnhancementEngine method populateWithEntity.

/**
     * Fetch the OWLOntology containing the graph associated to an entity from Linked Data. It uses the Entity
     * Hub for accessing LOD and fetching entities.
     * 
     * @param entityURI
     *            {@link String}
     * @return the {@link OWLOntology} of the entity
     */
private Graph populateWithEntity(String entityURI, Graph target) {
    log.debug("Requesting signature of entity {}", entityURI);
    Graph graph = target != null ? target : new IndexedGraph();
    // Query the Entity Hub
    Entity signature = referencedSiteManager.getEntity(entityURI);
    if (signature != null) {
        RdfRepresentation rdfSignature = RdfValueFactory.getInstance().toRdfRepresentation(signature.getRepresentation());
        graph.addAll(rdfSignature.getRdfGraph());
    }
    return graph;
}
Also used : Entity(org.apache.stanbol.entityhub.servicesapi.model.Entity) IndexedGraph(org.apache.stanbol.commons.indexedgraph.IndexedGraph) Graph(org.apache.clerezza.commons.rdf.Graph) RdfRepresentation(org.apache.stanbol.entityhub.model.clerezza.RdfRepresentation) IndexedGraph(org.apache.stanbol.commons.indexedgraph.IndexedGraph)

Example 8 with RdfRepresentation

use of org.apache.stanbol.entityhub.model.clerezza.RdfRepresentation in project stanbol by apache.

the class ExistingClerezzaGraphTest method testModificationsOnReadWirteYard.

@Test
public void testModificationsOnReadWirteYard() throws YardException {
    RdfRepresentation rep = RdfValueFactory.getInstance().createRepresentation("http://www.test.org/addedEntity");
    rep.addReference(RDF.type.getUnicodeString(), SKOS.Concept.getUnicodeString());
    rep.addNaturalText(SKOS.prefLabel.getUnicodeString(), "added Entity", "en");
    rep.addNaturalText(SKOS.prefLabel.getUnicodeString(), "hinzugefüte Entity", "de");
    readwriteYard.store(rep);
    //test that the data where added and modified in the read/wirte grpah
    validateEntity(readwriteYard, singletonMap(rep.getNode(), rep.getRdfGraph()).entrySet().iterator().next());
    readwriteYard.remove(rep.getId());
    Assert.assertNull("Representation " + rep.getId() + " was not correctly " + "deleted from " + readwriteYard.getId(), readwriteYard.getRepresentation(rep.getId()));
}
Also used : RdfRepresentation(org.apache.stanbol.entityhub.model.clerezza.RdfRepresentation) Test(org.junit.Test)

Example 9 with RdfRepresentation

use of org.apache.stanbol.entityhub.model.clerezza.RdfRepresentation in project stanbol by apache.

the class ExistingClerezzaGraphTest method validateEntity.

/**
     * Used by {@link #testRetrival()} to validate that an Entity is correctly
     * retrieved by the tested {@link ClerezzaYard}s.
     * @param entity key - URI; value - expected RDF data
     */
private void validateEntity(ClerezzaYard yard, Entry<IRI, Graph> entity) {
    Representation rep = yard.getRepresentation(entity.getKey().getUnicodeString());
    assertNotNull("The Representation for " + entity.getKey() + "is missing in the " + yard.getId(), rep);
    assertTrue("RdfRepresentation expected", rep instanceof RdfRepresentation);
    Graph repGraph = ((RdfRepresentation) rep).getRdfGraph();
    for (Iterator<Triple> triples = entity.getValue().iterator(); triples.hasNext(); ) {
        Triple triple = triples.next();
        assertTrue("Data of Representation " + entity.getKey() + "is missing the triple " + triple, repGraph.remove(triple));
    }
    assertTrue(repGraph.size() + " unexpected Triples are present in the " + "Representation of Entity " + entity.getKey(), repGraph.isEmpty());
}
Also used : Triple(org.apache.clerezza.commons.rdf.Triple) ImmutableGraph(org.apache.clerezza.commons.rdf.ImmutableGraph) SimpleGraph(org.apache.clerezza.commons.rdf.impl.utils.simple.SimpleGraph) Graph(org.apache.clerezza.commons.rdf.Graph) RdfRepresentation(org.apache.stanbol.entityhub.model.clerezza.RdfRepresentation) RdfRepresentation(org.apache.stanbol.entityhub.model.clerezza.RdfRepresentation) Representation(org.apache.stanbol.entityhub.servicesapi.model.Representation)

Example 10 with RdfRepresentation

use of org.apache.stanbol.entityhub.model.clerezza.RdfRepresentation in project stanbol by apache.

the class ClerezzaYard method store.

protected final Representation store(Representation representation, boolean allowCreate, boolean canNotCreateIsError) throws IllegalArgumentException, YardException {
    if (representation == null) {
        return null;
    }
    log.debug("store Representation " + representation.getId());
    IRI id = new IRI(representation.getId());
    final Lock writeLock = writeLockGraph();
    try {
        Iterator<Triple> current = graph.filter(id, null, null);
        boolean contains = current.hasNext();
        while (current.hasNext()) {
            //delete current
            current.next();
            current.remove();
        }
        if (!contains && !allowCreate) {
            if (canNotCreateIsError) {
                throw new IllegalArgumentException("Parsed Representation " + representation.getId() + " in not managed by this Yard " + getName() + "(id=" + getId() + ")");
            } else {
                return null;
            }
        }
        //get the graph for the Representation and add it to the store
        RdfRepresentation toAdd = ((RdfValueFactory) getValueFactory()).toRdfRepresentation(representation);
        //log.info("  > add "+toAdd.size()+" triples to Yard "+getId());
        Iterator<Triple> it = toAdd.getRdfGraph().filter(toAdd.getNode(), null, null);
        if (!it.hasNext()) {
            //TODO: Note somewhere that this Triple is reserved and MUST NOT
            //      be used by externally.
            graph.add(new TripleImpl(toAdd.getNode(), MANAGED_REPRESENTATION, TRUE_LITERAL));
        } else {
            while (it.hasNext()) {
                graph.add(it.next());
            }
        }
        return toAdd;
    } finally {
        writeLock.unlock();
    }
}
Also used : Triple(org.apache.clerezza.commons.rdf.Triple) IRI(org.apache.clerezza.commons.rdf.IRI) BlankNodeOrIRI(org.apache.clerezza.commons.rdf.BlankNodeOrIRI) RdfRepresentation(org.apache.stanbol.entityhub.model.clerezza.RdfRepresentation) TripleImpl(org.apache.clerezza.commons.rdf.impl.utils.TripleImpl) RdfValueFactory(org.apache.stanbol.entityhub.model.clerezza.RdfValueFactory) Lock(java.util.concurrent.locks.Lock)

Aggregations

RdfRepresentation (org.apache.stanbol.entityhub.model.clerezza.RdfRepresentation)10 Graph (org.apache.clerezza.commons.rdf.Graph)4 RdfValueFactory (org.apache.stanbol.entityhub.model.clerezza.RdfValueFactory)4 SimpleGraph (org.apache.clerezza.commons.rdf.impl.utils.simple.SimpleGraph)3 Test (org.junit.Test)3 IRI (org.apache.clerezza.commons.rdf.IRI)2 Triple (org.apache.clerezza.commons.rdf.Triple)2 TripleImpl (org.apache.clerezza.commons.rdf.impl.utils.TripleImpl)2 IndexedGraph (org.apache.stanbol.commons.indexedgraph.IndexedGraph)2 Representation (org.apache.stanbol.entityhub.servicesapi.model.Representation)2 TreeMap (java.util.TreeMap)1 Lock (java.util.concurrent.locks.Lock)1 BlankNodeOrIRI (org.apache.clerezza.commons.rdf.BlankNodeOrIRI)1 ImmutableGraph (org.apache.clerezza.commons.rdf.ImmutableGraph)1 DereferenceException (org.apache.stanbol.enhancer.engines.dereference.DereferenceException)1 FieldQueryImpl (org.apache.stanbol.entityhub.core.query.FieldQueryImpl)1 RdfReference (org.apache.stanbol.entityhub.model.clerezza.RdfReference)1 EntityhubException (org.apache.stanbol.entityhub.servicesapi.EntityhubException)1 Entity (org.apache.stanbol.entityhub.servicesapi.model.Entity)1 Text (org.apache.stanbol.entityhub.servicesapi.model.Text)1