Search in sources :

Example 1 with CreateProperty

use of nl.knaw.huygens.timbuctoo.core.dto.rdf.CreateProperty in project timbuctoo by HuygensING.

the class PropertyFactoryTest method fromRdfPredicateWillNotCreateTheSameClientNameTwice.

@Test
public void fromRdfPredicateWillNotCreateTheSameClientNameTwice() {
    ValueTypeInUse valueType1 = ImmutableValueTypeInUse.builder().typeUri("http://example.org/type1").addEntitiesConnected("entity1", "entity2").build();
    List<PredicateInUse> predicates = Lists.newArrayList(ImmutablePredicateInUse.builder().predicateUri("http://example.org/localName").addValueTypes(valueType1).build(), ImmutablePredicateInUse.builder().predicateUri("http://example.com/localName").addValueTypes(valueType1).build());
    List<CreateProperty> properties = instance.fromPredicates(predicates);
    assertThat(properties, containsInAnyOrder(allOf(hasProperty("clientName", equalTo("localName")), hasProperty("rdfUri", equalTo("http://example.org/localName"))), allOf(hasProperty("clientName", equalTo("http://example.com/localName")), hasProperty("rdfUri", equalTo("http://example.com/localName")))));
}
Also used : CreateProperty(nl.knaw.huygens.timbuctoo.core.dto.rdf.CreateProperty) ValueTypeInUse(nl.knaw.huygens.timbuctoo.core.dto.rdf.ValueTypeInUse) ImmutableValueTypeInUse(nl.knaw.huygens.timbuctoo.core.dto.rdf.ImmutableValueTypeInUse) PredicateInUse(nl.knaw.huygens.timbuctoo.core.dto.rdf.PredicateInUse) ImmutablePredicateInUse(nl.knaw.huygens.timbuctoo.core.dto.rdf.ImmutablePredicateInUse) Test(org.junit.Test)

Example 2 with CreateProperty

use of nl.knaw.huygens.timbuctoo.core.dto.rdf.CreateProperty in project timbuctoo by HuygensING.

the class RdfImportSessionTest method closeCreatesPropertyDescriptionsForEachPredicate.

@Test
public void closeCreatesPropertyDescriptionsForEachPredicate() {
    List<PredicateInUse> predicates = Lists.newArrayList();
    given(dataStoreOperations.getPredicatesFor(any(Collection.class))).willReturn(predicates);
    PropertyFactory propertyFactory = mock(PropertyFactory.class);
    ArrayList<CreateProperty> createProperties = Lists.newArrayList();
    given(propertyFactory.fromPredicates(predicates)).willReturn(createProperties);
    RdfImportSession instance = rdfImportSessionWithPropertyFactory(VRE_NAME, dataStoreOperations, propertyFactory);
    instance.commit();
    instance.close();
    verify(propertyFactory).fromPredicates(predicates);
    verify(dataStoreOperations).addPropertiesToCollection(any(Collection.class), eq(createProperties));
}
Also used : CreateProperty(nl.knaw.huygens.timbuctoo.core.dto.rdf.CreateProperty) RdfImportSessionStubs.rdfImportSessionWithPropertyFactory(nl.knaw.huygens.timbuctoo.core.RdfImportSessionStubs.rdfImportSessionWithPropertyFactory) PropertyFactory(nl.knaw.huygens.timbuctoo.core.rdf.PropertyFactory) CreateCollection(nl.knaw.huygens.timbuctoo.core.dto.CreateCollection) Collection(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection) PredicateInUse(nl.knaw.huygens.timbuctoo.core.dto.rdf.PredicateInUse) Test(org.junit.Test)

Example 3 with CreateProperty

use of nl.knaw.huygens.timbuctoo.core.dto.rdf.CreateProperty in project timbuctoo by HuygensING.

the class PropertyFactory method convertToProperty.

private CreateProperty convertToProperty(PredicateInUse pred) {
    Stack<ValueTypeInUse> valueTypes = pred.getValueTypes().stream().sorted(comparingInt(o -> o.getEntitiesConnected().size())).collect(toCollection(Stack::new));
    ValueTypeInUse type = valueTypes.pop();
    valueTypes.forEach(vt -> vt.getEntitiesConnected().forEach(e -> importErrorReporter.entityHasWrongTypeForProperty(e, pred.getPredicateUri(), type.getTypeUri(), vt.getTypeUri())));
    return ImmutableCreateProperty.builder().clientName(getPredicateName(pred)).rdfUri(pred.getPredicateUri()).typeUri(type.getTypeUri()).propertyType(getPropertyType(pred.getPredicateUri(), type)).build();
}
Also used : Comparator.comparingInt(java.util.Comparator.comparingInt) ImmutableCreateProperty(nl.knaw.huygens.timbuctoo.core.dto.rdf.ImmutableCreateProperty) PredicateInUse(nl.knaw.huygens.timbuctoo.core.dto.rdf.PredicateInUse) RdfImportErrorReporter(nl.knaw.huygens.timbuctoo.core.RdfImportErrorReporter) Set(java.util.Set) ValueTypeInUse(nl.knaw.huygens.timbuctoo.core.dto.rdf.ValueTypeInUse) CreateProperty(nl.knaw.huygens.timbuctoo.core.dto.rdf.CreateProperty) Stack(java.util.Stack) HashSet(java.util.HashSet) Collectors.toCollection(java.util.stream.Collectors.toCollection) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) Util(org.apache.jena.rdf.model.impl.Util) RdfPropertyConverterFactory(nl.knaw.huygens.timbuctoo.rdf.conversion.RdfPropertyConverterFactory) ValueTypeInUse(nl.knaw.huygens.timbuctoo.core.dto.rdf.ValueTypeInUse)

Example 4 with CreateProperty

use of nl.knaw.huygens.timbuctoo.core.dto.rdf.CreateProperty in project timbuctoo by HuygensING.

the class PropertyFactory method fromPredicates.

public List<CreateProperty> fromPredicates(List<PredicateInUse> predicates) {
    List<CreateProperty> result = predicates.stream().map(pred -> convertToProperty(pred)).collect(toList());
    Set<String> encounteredLocalnames = new HashSet<>();
    for (int i = 0; i < result.size(); i++) {
        CreateProperty createProperty = result.get(i);
        if (encounteredLocalnames.contains(createProperty.getClientName())) {
            createProperty = ImmutableCreateProperty.copyOf(createProperty).withClientName(createProperty.getRdfUri());
            result.set(i, createProperty);
        }
        encounteredLocalnames.add(createProperty.getClientName());
    }
    return result;
}
Also used : ImmutableCreateProperty(nl.knaw.huygens.timbuctoo.core.dto.rdf.ImmutableCreateProperty) CreateProperty(nl.knaw.huygens.timbuctoo.core.dto.rdf.CreateProperty) Comparator.comparingInt(java.util.Comparator.comparingInt) ImmutableCreateProperty(nl.knaw.huygens.timbuctoo.core.dto.rdf.ImmutableCreateProperty) PredicateInUse(nl.knaw.huygens.timbuctoo.core.dto.rdf.PredicateInUse) RdfImportErrorReporter(nl.knaw.huygens.timbuctoo.core.RdfImportErrorReporter) Set(java.util.Set) ValueTypeInUse(nl.knaw.huygens.timbuctoo.core.dto.rdf.ValueTypeInUse) CreateProperty(nl.knaw.huygens.timbuctoo.core.dto.rdf.CreateProperty) Stack(java.util.Stack) HashSet(java.util.HashSet) Collectors.toCollection(java.util.stream.Collectors.toCollection) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) Util(org.apache.jena.rdf.model.impl.Util) RdfPropertyConverterFactory(nl.knaw.huygens.timbuctoo.rdf.conversion.RdfPropertyConverterFactory) HashSet(java.util.HashSet)

Aggregations

CreateProperty (nl.knaw.huygens.timbuctoo.core.dto.rdf.CreateProperty)4 PredicateInUse (nl.knaw.huygens.timbuctoo.core.dto.rdf.PredicateInUse)4 ValueTypeInUse (nl.knaw.huygens.timbuctoo.core.dto.rdf.ValueTypeInUse)3 Comparator.comparingInt (java.util.Comparator.comparingInt)2 HashSet (java.util.HashSet)2 List (java.util.List)2 Set (java.util.Set)2 Stack (java.util.Stack)2 Collectors.toCollection (java.util.stream.Collectors.toCollection)2 Collectors.toList (java.util.stream.Collectors.toList)2 RdfImportErrorReporter (nl.knaw.huygens.timbuctoo.core.RdfImportErrorReporter)2 ImmutableCreateProperty (nl.knaw.huygens.timbuctoo.core.dto.rdf.ImmutableCreateProperty)2 RdfPropertyConverterFactory (nl.knaw.huygens.timbuctoo.rdf.conversion.RdfPropertyConverterFactory)2 Util (org.apache.jena.rdf.model.impl.Util)2 Test (org.junit.Test)2 RdfImportSessionStubs.rdfImportSessionWithPropertyFactory (nl.knaw.huygens.timbuctoo.core.RdfImportSessionStubs.rdfImportSessionWithPropertyFactory)1 CreateCollection (nl.knaw.huygens.timbuctoo.core.dto.CreateCollection)1 Collection (nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection)1 ImmutablePredicateInUse (nl.knaw.huygens.timbuctoo.core.dto.rdf.ImmutablePredicateInUse)1 ImmutableValueTypeInUse (nl.knaw.huygens.timbuctoo.core.dto.rdf.ImmutableValueTypeInUse)1