Search in sources :

Example 6 with Predicate

use of nl.knaw.huygens.timbuctoo.v5.datastores.schemastore.dto.Predicate in project timbuctoo by HuygensING.

the class JsonProvenanceToRdfPatch method collectReplacements.

public static Map<String, List<CursorQuad>> collectReplacements(JsonNode activity, QuadStore quadStore) {
    Map<String, List<CursorQuad>> toReplace = new HashMap<>();
    for (JsonNode revision : activity.get(PROV_GENERATES)) {
        final JsonNode replacements = revision.get(TIM_REPLACEMENTS);
        if (replacements != null) {
            String entity = revision.get(PROV_SPECIALIZATION_OF).get(0).get("@id").asText();
            List<CursorQuad> quads = new ArrayList<>();
            toReplace.put(revision.get("@id").asText(), quads);
            for (JsonNode replacement : replacements) {
                if (replacement.has(TIM_PREDICATE)) {
                    final String predicate = replacement.get(TIM_PREDICATE).get(0).get("@value").asText();
                    try (Stream<CursorQuad> source = quadStore.getQuads(entity, predicate, Direction.OUT, "")) {
                        source.forEach(quads::add);
                    }
                }
            }
        }
    }
    return toReplace;
}
Also used : HashMap(java.util.HashMap) CursorQuad(nl.knaw.huygens.timbuctoo.v5.datastores.quadstore.dto.CursorQuad) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) JsonNode(com.fasterxml.jackson.databind.JsonNode)

Example 7 with Predicate

use of nl.knaw.huygens.timbuctoo.v5.datastores.schemastore.dto.Predicate in project timbuctoo by HuygensING.

the class ViewConfigFetcher method makeDefaultViewConfig.

private ArrayList<Map> makeDefaultViewConfig(String collectionUri, Map<String, Type> schema, TypeNameStore typeNameStore) {
    ArrayList<Map> result = new ArrayList<>();
    Type collectionType = schema.get(collectionUri);
    if (collectionType == null) {
        LOG.error("The collectionUri " + collectionUri + " does not exist in the schema! (it does contain: [ " + schema.keySet().stream().collect(Collectors.joining(", ")) + " ]");
    } else {
        result.add(title(path(jsnA(jsnA(jsn("Entity"), jsn("title")), jsnA(jsn("Value"), jsn("value"))))));
        final String collectionGraphqlTypeWithoutDataSet = typeNameStore.makeGraphQlname(collectionUri);
        for (Predicate predicate : collectionType.getPredicates()) {
            final String predicateAsGraphqlProp = typeNameStore.makeGraphQlnameForPredicate(predicate.getName(), predicate.getDirection(), predicate.isList());
            ArrayNode predicateReference = jsnA(jsnA(jsn(collectionGraphqlTypeWithoutDataSet), jsn(predicateAsGraphqlProp)));
            if (predicate.isList()) {
                predicateReference.add(jsnA(jsn("items"), jsn("items")));
            }
            String title = "";
            if (predicate.getDirection() == Direction.IN) {
                title = "⬅︎ ";
            }
            title += typeNameStore.shorten(predicate.getName());
            if (predicate.getReferenceTypes().values().stream().anyMatch(x -> x > 0)) {
                // it's at least sometimes a link
                result.add(keyValue(title, internalLink(path(pushImm(predicateReference, jsnA(jsn("Entity"), jsn("uri")))), path(pushImm(predicateReference, jsnA(jsn("Entity"), jsn("title")), jsnA(jsn("Value"), jsn("value")))))));
            }
            if (predicate.getValueTypes().values().stream().anyMatch(x -> x > 0)) {
                // it's at least sometimes a normal value
                result.add(keyValue(title, path(pushImm(predicateReference, jsnA(jsn("Value"), jsn("value"))))));
            }
        }
    }
    return result;
}
Also used : Type(nl.knaw.huygens.timbuctoo.v5.datastores.schemastore.dto.Type) ArrayList(java.util.ArrayList) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) Predicate(nl.knaw.huygens.timbuctoo.v5.datastores.schemastore.dto.Predicate)

Example 8 with Predicate

use of nl.knaw.huygens.timbuctoo.v5.datastores.schemastore.dto.Predicate in project timbuctoo by HuygensING.

the class DerivedSchemaTypeGenerator method makeGraphQlTypes.

public String makeGraphQlTypes(String rootType, Map<String, Type> types, TypeNameStore nameStore) {
    DerivedSchemaContainer typesContainer = new DerivedSchemaContainer(rootType, nameStore, this.argumentsHelper);
    // FIXME find a better way to register standard types to the schema of a data set
    typesContainer.valueType(RdfConstants.MARKDOWN);
    typesContainer.valueType(RdfConstants.STRING);
    typesContainer.valueType(RdfConstants.URI);
    for (Type type : types.values()) {
        typesContainer.openObjectType(type.getName());
        for (Predicate predicate : type.getPredicates()) {
            fieldForDerivedType(predicate, typesContainer);
        }
        typesContainer.closeObjectType(type.getName());
    }
    return typesContainer.getSchema();
}
Also used : Type(nl.knaw.huygens.timbuctoo.v5.datastores.schemastore.dto.Type) Predicate(nl.knaw.huygens.timbuctoo.v5.datastores.schemastore.dto.Predicate)

Example 9 with Predicate

use of nl.knaw.huygens.timbuctoo.v5.datastores.schemastore.dto.Predicate in project timbuctoo by HuygensING.

the class JsonProvenanceToRdfPatchTest method retractsPreviousRevision.

@Test
public void retractsPreviousRevision() throws Exception {
    String testRetractsRevision = "{\n" + "   \"@type\":\"prov:Activity\",\n" + "   \"http://www.w3.org/ns/prov#generates\":[\n" + "      {\n" + "         \"@type\":\"prov:Entity\",\n" + "         \"@id\":\"_:b2\",\n" + "         \"specializationOf\":{\n" + "            \"@id\":\"http://example.com/the/actual/entitys\"\n" + "         },\n" + "         \"wasRevisionOf\":{\n" + "            \"@id\":\"http://example.org/revision1\"\n" + "         },\n" + "         \"replacements\":[\n" + "            {\n" + "               \"@type\":\"http://timbuctoo.huygens.knaw.nl/v5/vocabulary#mutation\",\n" + "               \"predicate\":\"http://example.org/pred1\",\n" + "               \"value\":\"value1\"\n" + "            }\n" + "         ]\n" + "      }\n" + "   ],\n" + context + "}";
    QuadStore testQuadStore = new DummyQuadStore().with("http://example.org/revision1", PROV_SPECIALIZATION_OF, "http://example.com/the/actual/entitys", null).with("http://example.com/the/actual/entitys", TIM_LATEST_REVISION, "http://example.org/revision1");
    JsonProvenanceToRdfPatch creator = fromCurrentState(new DocumentLoader(), testRetractsRevision, testQuadStore, EDITOR_URI, "test", CLOCK);
    creator.sendQuads(basicRdfPatchSerializer, s -> {
    }, null);
    List<String> filteredResult = Lists.newArrayList(Collections2.filter(result, Predicates.containsPattern("latestRevision")));
    assertThat(filteredResult, containsInAnyOrder("-<http://example.com/the/actual/entitys> <" + TIM_LATEST_REVISION + "> <http://example.org/revision1" + "> <" + defaultGraph + "> .\n", "+<http://example.com/the/actual/entitys> <" + TIM_LATEST_REVISION + "> <http://timbuctoo.huygens.knaw.nl/static/v5/skolemized/test/b1> <" + defaultGraph + "> .\n"));
}
Also used : QuadStore(nl.knaw.huygens.timbuctoo.v5.datastores.quadstore.QuadStore) DocumentLoader(com.github.jsonldjava.core.DocumentLoader) Test(org.junit.Test)

Example 10 with Predicate

use of nl.knaw.huygens.timbuctoo.v5.datastores.schemastore.dto.Predicate in project timbuctoo by HuygensING.

the class PredicateTest method mergeMaintainsHasBeenListProperty.

@Test
public void mergeMaintainsHasBeenListProperty() throws Exception {
    Predicate predicate1 = createPredicate("predicate", Direction.OUT, "testOwner");
    predicate1.setHasBeenList(true);
    Predicate predicate2 = createPredicate("predicate", Direction.OUT, "testOwner");
    predicate2.setHasBeenList(false);
    Predicate mergedPredicate = predicate1.merge(predicate2);
    assertThat(mergedPredicate.hasBeenList(), Matchers.is(true));
}
Also used : Predicate(nl.knaw.huygens.timbuctoo.v5.datastores.schemastore.dto.Predicate) Test(org.junit.Test)

Aggregations

Predicate (nl.knaw.huygens.timbuctoo.v5.datastores.schemastore.dto.Predicate)16 Test (org.junit.Test)12 RdfProcessingFailedException (nl.knaw.huygens.timbuctoo.v5.dataset.exceptions.RdfProcessingFailedException)6 Type (nl.knaw.huygens.timbuctoo.v5.datastores.schemastore.dto.Type)6 IOException (java.io.IOException)5 HashMap (java.util.HashMap)5 Map (java.util.Map)5 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)4 QuadStore (nl.knaw.huygens.timbuctoo.v5.datastores.quadstore.QuadStore)4 ValueFactory (org.eclipse.rdf4j.model.ValueFactory)4 SimpleValueFactory (org.eclipse.rdf4j.model.impl.SimpleValueFactory)4 SAXException (org.xml.sax.SAXException)4 DocumentLoader (com.github.jsonldjava.core.DocumentLoader)3 DatabaseWriteException (nl.knaw.huygens.timbuctoo.v5.berkeleydb.exceptions.DatabaseWriteException)3 CursorQuad (nl.knaw.huygens.timbuctoo.v5.datastores.quadstore.dto.CursorQuad)3 Direction (nl.knaw.huygens.timbuctoo.v5.datastores.quadstore.dto.Direction)3 StringValue (graphql.language.StringValue)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 ChangeType (nl.knaw.huygens.timbuctoo.v5.datastores.quadstore.dto.ChangeType)2