use of nl.knaw.huygens.timbuctoo.v5.datastores.schemastore.dto.Predicate in project timbuctoo by HuygensING.
the class RdfDescriptionSaver method addValue.
@Override
public void addValue(String subject, String predicate, String value, String dataType, String graph) throws RdfProcessingFailedException {
try {
if (Objects.equals(subject, baseUri) && isDescriptionPredicate(predicate)) {
ValueFactory vf = SimpleValueFactory.getInstance();
model.add(vf.createIRI(subject), vf.createIRI(predicate), vf.createLiteral(value));
}
} catch (Exception e) {
throw new RdfProcessingFailedException(e);
}
}
use of nl.knaw.huygens.timbuctoo.v5.datastores.schemastore.dto.Predicate in project timbuctoo by HuygensING.
the class BdbSchemaStore method finish.
@Override
public void finish() {
LOG.info("Finished processing entities");
importStatus.setStatus("Finished processing entities");
// Step 3: Add type information to inverse predicates
for (Map.Entry<String, Type> typeEntry : types.entrySet()) {
Type type = typeEntry.getValue();
String typeName = typeEntry.getKey();
for (Predicate predicate : type.getPredicates()) {
predicate.finish();
if (predicate.getDirection() == Direction.IN) {
continue;
}
for (String referenceType : predicate.getReferenceTypes().keySet()) {
try {
types.get(referenceType).getPredicate(predicate.getName(), // There must be an inverse for each outward predicate
Direction.IN).incReferenceType(type.getName(), 1);
} catch (Exception e) {
String cause = "Referenced type " + referenceType + " not found";
try {
if (types.containsKey(referenceType)) {
cause = "type does not have the inverse predicate " + predicate.getName();
if (types.get(referenceType).getPredicate(predicate.getName(), Direction.IN) != null) {
cause = "Something failed during addreferencetype(" + typeName + ")";
}
}
LOG.error("Error during inverse generation (ignored): " + cause, e);
importStatus.addError("Error during inverse generation (ignored): " + cause, e);
} catch (Exception e2) {
LOG.error("Error during inverse generation " + cause, e);
importStatus.addError("Error during inverse generation " + cause, e);
LOG.error("Error during recovery generation ", e2);
importStatus.addError("Error during recovery generation ", e2);
}
}
}
}
}
try {
try {
String serializedValue = objectMapper.writeValueAsString(types);
dataStore.setValue(serializedValue);
dataStore.commit();
stableTypes = readTypes(serializedValue);
} catch (IOException | DatabaseWriteException e) {
throw new SchemaUpdateException(e);
}
} catch (SchemaUpdateException e) {
e.printStackTrace();
}
}
use of nl.knaw.huygens.timbuctoo.v5.datastores.schemastore.dto.Predicate in project timbuctoo by HuygensING.
the class BdbSchemaStore method updatePredicateType.
public void updatePredicateType(Type type, CursorQuad quad, boolean inc, ChangeFetcher changeFetcher) {
final Predicate predicate = type.getOrCreatePredicate(quad.getPredicate(), quad.getDirection());
if (quad.getValuetype().isPresent()) {
predicate.incValueType(quad.getValuetype().get(), inc ? 1 : -1);
} else {
try (Stream<CursorQuad> typeQs = changeFetcher.getPredicates(quad.getObject(), RDF_TYPE, OUT, !inc, true, inc)) {
boolean[] hadType = new boolean[] { false };
typeQs.forEach(typeQ -> {
hadType[0] = true;
predicate.incReferenceType(typeQ.getObject(), inc ? 1 : -1);
});
if (!hadType[0]) {
predicate.incReferenceType(UNKNOWN, inc ? 1 : -1);
}
}
}
}
use of nl.knaw.huygens.timbuctoo.v5.datastores.schemastore.dto.Predicate in project timbuctoo by HuygensING.
the class PredicateMutationRdfPatcher method sendQuads.
@Override
public void sendQuads(RdfPatchSerializer saver, Consumer<String> importStatusConsumer, DataSet dataSet) throws LogStorageFailedException {
final QuadStore quadStore = dataSet.getQuadStore();
final Map<String, String> foundSubjects = new HashMap<>();
for (Map.Entry<UUID, PredicateMutation.SubjectFinder> entry : mutation.getSubjectFinders().entrySet()) {
foundSubjects.put(entry.getKey().toString(), entry.getValue().getSubject(quadStore));
}
for (CursorQuad newValue : mutation.getFullRetractions()) {
final String subject = foundSubjects.getOrDefault(newValue.getSubject(), newValue.getSubject());
final String predicate = newValue.getPredicate();
final Direction direction = newValue.getDirection();
try (Stream<CursorQuad> quads = quadStore.getQuads(subject, predicate, direction, "")) {
for (CursorQuad oldValue : (Iterable<CursorQuad>) quads::iterator) {
saver.delQuad(oldValue.getSubject(), oldValue.getPredicate(), oldValue.getObject(), oldValue.getValuetype().orElse(null), oldValue.getLanguage().orElse(null), null);
}
}
}
for (CursorQuad oldValue : mutation.getRetractions()) {
saver.delQuad(foundSubjects.getOrDefault(oldValue.getSubject(), oldValue.getSubject()), oldValue.getPredicate(), foundSubjects.getOrDefault(oldValue.getObject(), oldValue.getObject()), oldValue.getValuetype().orElse(null), oldValue.getLanguage().orElse(null), null);
}
for (CursorQuad newValue : mutation.getAdditions()) {
if (newValue.getObject() != null) {
saver.onQuad(foundSubjects.getOrDefault(newValue.getSubject(), newValue.getSubject()), newValue.getPredicate(), foundSubjects.getOrDefault(newValue.getObject(), newValue.getObject()), newValue.getValuetype().orElse(null), newValue.getLanguage().orElse(null), null);
}
}
}
use of nl.knaw.huygens.timbuctoo.v5.datastores.schemastore.dto.Predicate in project timbuctoo by HuygensING.
the class MergeSchemas method mergeSchema.
public Map<String, Type> mergeSchema(Map<String, Type> generatedSchema, Map<String, Type> customSchema) {
Map<String, Type> mergedSchema = generatedSchema;
Collection<Predicate> mergedPredicates;
for (Map.Entry<String, Type> entry : customSchema.entrySet()) {
mergedPredicates = new HashSet<>();
if (mergedSchema.get(entry.getKey()) != null) {
for (Predicate customPredicate : entry.getValue().getPredicates()) {
if (mergedSchema.get(entry.getKey()).getPredicate(customPredicate.getName(), customPredicate.getDirection()) != null) {
Predicate generatedPredicate = mergedSchema.get(entry.getKey()).getPredicate(customPredicate.getName(), customPredicate.getDirection());
Predicate mergedPredicate = generatedPredicate.merge(customPredicate);
mergedPredicate.setIsExplicit(true);
mergedPredicates.add(mergedPredicate);
} else {
mergedPredicates.add(customPredicate);
}
}
mergedSchema.get(entry.getKey()).setPredicates(mergedPredicates);
} else {
mergedSchema.put(entry.getKey(), entry.getValue());
}
}
return mergedSchema;
}
Aggregations