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();
}
}
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;
}
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()));
}
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());
}
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();
}
}
Aggregations