Java Code Examples for org.apache.jena.rdf.model.ResourceFactory#createProperty()

The following examples show how to use org.apache.jena.rdf.model.ResourceFactory#createProperty() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestCaseGroupAnd.java    From RDFUnit with Apache License 2.0 6 votes vote down vote up
public TestCaseGroupAnd(@NonNull Set<? extends TargetBasedTestCase> testCases) {
    assert(! testCases.isEmpty());
    target = testCases.iterator().next().getTarget();
    assert(testCases.stream().map(TargetBasedTestCase::getTarget).noneMatch(x -> x != target));

    this.resource = ResourceFactory.createProperty(JenaUtils.getUniqueIri());
    this.testCases = ImmutableSet.copyOf(testCases);

    List<TestCaseAnnotation> innerAnnotations = testCases.stream().map(GenericTestCase::getTestCaseAnnotation).collect(Collectors.toList());
    String description = "A logical AND constraint component containing the following rules:";
    if (innerAnnotations.size() == 1) {
        description = "";
    }
    description += innerAnnotations.stream().map(TestCaseAnnotation::getDescription).collect(Collectors.joining(", "));
    this.testCaseAnnotation = new TestCaseAnnotation(
            this.resource,
            innerAnnotations.stream().map(TestCaseAnnotation::getGenerated).findFirst().orElse(TestGenerationType.AutoGenerated),
            null,
            innerAnnotations.stream().map(TestCaseAnnotation::getAppliesTo).findFirst().orElse(TestAppliesTo.Dataset),
            innerAnnotations.stream().map(TestCaseAnnotation::getSourceUri).findFirst().orElse(SHACL.namespace),
            innerAnnotations.stream().flatMap(t -> t.getReferences().stream()).collect(Collectors.toSet()),
            description,
            RLOGLevel.ERROR, // TODO probably needs to provided from shape
            ImmutableSet.of()   //TODO do I have to add annotations by default?
    );
}
 
Example 2
Source File: String2Node.java    From quetzal with Eclipse Public License 2.0 6 votes vote down vote up
public String2Node(String type, String value, short datatype)
   {
if(value.equals("NULL")){
 node = null;
}
else if (value.startsWith(Constants.PREFIX_BLANK_NODE))
      {
      AnonId id = new AnonId(value.substring(Constants.PREFIX_BLANK_NODE.length()));
      node = ModelFactory.createDefaultModel().createResource(id);
      }
   else if (type.equals(Constants.NAME_COLUMN_SUBJECT))
      {
      node = ResourceFactory.createResource(value);
      }
   else if (type.equals(Constants.NAME_COLUMN_PREDICATE))
      {
      node = ResourceFactory.createProperty(value);
      }
   else if (type.equals(Constants.NAME_COLUMN_OBJECT))
      {
      assignLiteral(value, datatype);
      }
   }
 
Example 3
Source File: String2Node.java    From quetzal with Eclipse Public License 2.0 6 votes vote down vote up
public String2Node(String type, String value)
  {
if(value.equals("NULL")){
 node = null;
}
else if (value.startsWith(Constants.PREFIX_BLANK_NODE))
     {
     AnonId id = new AnonId(value.substring(Constants.PREFIX_BLANK_NODE.length()));
     node = ModelFactory.createDefaultModel().createResource(id);
     }
  else if (type.equals(Constants.NAME_COLUMN_SUBJECT))
     {
     node = ResourceFactory.createResource(value);
     }
  else if (type.equals(Constants.NAME_COLUMN_PREDICATE))
     {
     node = ResourceFactory.createProperty(value);
     }
  else if (type.equals(Constants.NAME_COLUMN_OBJECT))
     {
     assert (false); // mdb change code call other ctor
     }
  }
 
Example 4
Source File: IndexRequestProcessorForTPFs.java    From Server.Java with MIT License 5 votes vote down vote up
/**
 *
 * @param s
 * @param p
 * @param o
 * @param offset
 * @param limit
 * @return
 */
@Override
protected ILinkedDataFragment createFragment(
                   final ITriplePatternElement<RDFNode,String,String> s,
                   final ITriplePatternElement<RDFNode,String,String> p,
                   final ITriplePatternElement<RDFNode,String,String> o,
                   final long offset,
                   final long limit )
{
    // FIXME: The following algorithm is incorrect for cases in which
    //        the requested triple pattern contains a specific variable
    //        multiple times;
    //        e.g., (?x foaf:knows ?x ) or (_:bn foaf:knows _:bn)
    // see https://github.com/LinkedDataFragments/Server.Java/issues/25

    final Resource subject   = s.isVariable() ? null
                                              : s.asConstantTerm().asResource();
    final Property predicate = p.isVariable() ? null
                                              : ResourceFactory.createProperty(p.asConstantTerm().asResource().getURI());
    final RDFNode object     = o.isVariable() ? null
                                              : o.asConstantTerm();

    StmtIterator listStatements = model.listStatements(subject, predicate, object);
    Model result = ModelFactory.createDefaultModel();

    long index = 0;
    while (listStatements.hasNext() && index < offset) {
        listStatements.next();
        index++;
    }

    while (listStatements.hasNext() && index < (offset + limit)) {
        result.add(listStatements.next());
    }

    final boolean isLastPage = ( result.size() < offset + limit );
    return createTriplePatternFragment( result, result.size(), isLastPage );
}
 
Example 5
Source File: ShapePathReaderTest.java    From RDFUnit with Apache License 2.0 5 votes vote down vote up
@Parameterized.Parameters(name= "{index}: Path: {1}")
public static Collection<Object[]> resources() throws RdfReaderException {
    Model model = RdfReaderFactory.createResourceReader("/org/aksw/rdfunit/model/readers/shacl/ShapePathReaderTest.ttl").read();
    Collection<Object[]> parameters = new ArrayList<>();
    Property pathProperty = ResourceFactory.createProperty("http://ex.com/path");
    Property pathExprProperty = ResourceFactory.createProperty("http://ex.com/pathExp");
    for (Resource node: model.listSubjectsWithProperty(pathProperty).toList()) {
        Resource path = node.getPropertyResourceValue(pathProperty);
        String pathExpr = node.getProperty(pathExprProperty).getObject().asLiteral().getLexicalForm();
        parameters.add(new Object[] {path, pathExpr});
    }
    return parameters;
}
 
Example 6
Source File: TestCaseGroupXone.java    From RDFUnit with Apache License 2.0 5 votes vote down vote up
public TestCaseGroupXone(@NonNull Set<? extends TargetBasedTestCase> testCases) {
    assert(! testCases.isEmpty());
    target = testCases.iterator().next().getTarget();
    assert(testCases.stream().map(TargetBasedTestCase::getTarget).noneMatch(x -> x != target));
    this.resource = ResourceFactory.createProperty(JenaUtils.getUniqueIri());
    this.testCases = ImmutableSet.copyOf(Stream.concat(testCases.stream(), Stream.of(new AlwaysFailingTestCase(this.target))).collect(Collectors.toSet()));     // adding always failing test
}
 
Example 7
Source File: ResultAnnotationImpl.java    From RDFUnit with Apache License 2.0 4 votes vote down vote up
public Builder(String elementUri, String propertyIri) {
    this(ResourceFactory.createResource(elementUri), ResourceFactory.createProperty(propertyIri));
}
 
Example 8
Source File: SparqlConstraintImpl.java    From RDFUnit with Apache License 2.0 4 votes vote down vote up
private Resource createTestCaseResource() {
    // FIXME temporary solution until we decide how to build stable unique test uris
    return ResourceFactory.createProperty(JenaUtils.getUniqueIri());
}
 
Example 9
Source File: PROV.java    From RDFUnit with Apache License 2.0 4 votes vote down vote up
private static Property property(String local) {
    return ResourceFactory.createProperty(namespace, local);
}
 
Example 10
Source File: RLOG.java    From RDFUnit with Apache License 2.0 4 votes vote down vote up
private static Property property(String local) {
    return ResourceFactory.createProperty(namespace, local);
}
 
Example 11
Source File: SHACL_TEST.java    From RDFUnit with Apache License 2.0 4 votes vote down vote up
private static Property property(String local) {
    return ResourceFactory.createProperty(namespace, local);
}
 
Example 12
Source File: TestCaseGroupNot.java    From RDFUnit with Apache License 2.0 4 votes vote down vote up
public TestCaseGroupNot(@NonNull Set<? extends TargetBasedTestCase> testCases) {
    assert(testCases.size() == 1);
    this.target = testCases.iterator().next().getTarget();
    this.resource = ResourceFactory.createProperty(JenaUtils.getUniqueIri());
    this.testCases = ImmutableSet.of(testCases.iterator().next(), new AlwaysFailingTestCase(this.target)); // adding always failing test
}
 
Example 13
Source File: SPIN.java    From RDFUnit with Apache License 2.0 4 votes vote down vote up
private static Property property(String local) {
    return ResourceFactory.createProperty(namespace, local);
}
 
Example 14
Source File: DBO.java    From gerbil with GNU Affero General Public License v3.0 4 votes vote down vote up
protected static final Property property(String local) {
    return ResourceFactory.createProperty(URI, local);
}
 
Example 15
Source File: RDFUNITv.java    From RDFUnit with Apache License 2.0 4 votes vote down vote up
private static Property property(String local) {
    return ResourceFactory.createProperty(namespace, local);
}
 
Example 16
Source File: DATA_ACCESS_TESTS.java    From RDFUnit with Apache License 2.0 4 votes vote down vote up
private static Property property(String local) {
    return ResourceFactory.createProperty(namespace, local);
}
 
Example 17
Source File: IndexRequestProcessorForTPFsTest.java    From Server.Java with MIT License 4 votes vote down vote up
/**
 * Check that the type void:Dataset is returned as a URI and not as a
 * literal
 */
@Test
public void shouldGiveVoidDatasetAsAURI() {
	final IDataSource datasource = new IDataSource() {
		@Override
		public String getDescription() {
			return "This is a dummy datasource";
		};

		@Override
		public IFragmentRequestParser getRequestParser() {
			return null;
		}

		@Override
		public IFragmentRequestProcessor getRequestProcessor() {
			return null;
		}

		@Override
		public String getTitle() {
			return "Dummy Dataource";
		}

		@Override
		public void close() {
			// does nothing
		}
	};
	final HashMap<String, IDataSource> datasources = new HashMap<String, IDataSource>();
	datasources.put("dummy", datasource);
	final String baseUrl = "dummy";
	final TestIndexRequestProcessor processor = new TestIndexRequestProcessor(
			baseUrl, datasources);
	final TriplePatternElementFactory<RDFNode, String, String> factory = new TriplePatternElementFactory<RDFNode, String, String>();
	final ITriplePatternFragmentRequest<RDFNode, String, String> request = new TriplePatternFragmentRequestImpl<RDFNode, String, String>(
			null, "dummy", false, 1, factory.createUnspecifiedVariable(),
			factory.createUnspecifiedVariable(),
			factory.createUnspecifiedVariable());
	final TestIndexRequestProcessor.TestWorker worker = processor
			.getTPFSpecificWorker(request);
	final ILinkedDataFragment fragment = worker.createRequestedFragment();
	final StmtIterator iterator = fragment.getTriples();
	final Collection<Statement> statements = new ArrayList<Statement>();
	while (iterator.hasNext()) {
		statements.add(iterator.next());
	}

	final Resource subject = ResourceFactory.createResource("dummy/dummy");
	final Property predicate = ResourceFactory
			.createProperty("http://www.w3.org/1999/02/22-rdf-syntax-ns#type");
	final Resource object = ResourceFactory
			.createResource("http://rdfs.org/ns/void#Dataset");
	final Statement expected = ResourceFactory.createStatement(subject,
			predicate, object);
	Assert.assertTrue("triple not contained in model",
			statements.contains(expected));
	processor.close();
}
 
Example 18
Source File: CommonResources.java    From Server.Java with MIT License 4 votes vote down vote up
private static Property createProperty(String uri) {
    return ResourceFactory.createProperty(uri);
}
 
Example 19
Source File: GERBIL.java    From gerbil with GNU Affero General Public License v3.0 4 votes vote down vote up
protected static final Property property(String local) {
    return ResourceFactory.createProperty(uri, local);
}
 
Example 20
Source File: CUBE.java    From gerbil with GNU Affero General Public License v3.0 4 votes vote down vote up
protected static final Property property(String local) {
    return ResourceFactory.createProperty(uri, local);
}