Java Code Examples for org.apache.jena.rdf.model.Resource

The following examples show how to use org.apache.jena.rdf.model.Resource. These examples are extracted from open source projects. 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
@Override
public void activate(final Collection<JenaPosLengthMatch> matches) throws IOException {
	final Model model = driver.getModel();
	final Property lengthProperty = model.getProperty(BASE_PREFIX + LENGTH);

	for (final JenaPosLengthMatch match : matches) {
		final Resource segment = match.getSegment();
		final int length = match.getLength().getInt();
		final int newLength = -length + 1;

		final Selector selector = new SimpleSelector(segment, lengthProperty, (RDFNode) null);
		final StmtIterator statementsToRemove = model.listStatements(selector);
		if (statementsToRemove.hasNext()) {
			final Statement oldStatement = statementsToRemove.next();
			model.remove(oldStatement);
		}
		
		final Statement newStatement = model.createLiteralStatement(segment, lengthProperty, newLength);
		model.add(newStatement);
	}
}
 
Example 2
Source Project: tools   Source File: TestSpdxPackage.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Test method for {@link org.spdx.rdfparser.model.SpdxPackage#setPackageVerificationCode(org.spdx.rdfparser.SpdxPackageVerificationCode)}.
 * @throws InvalidSPDXAnalysisException 
 */
@Test
public void testSetPackageVerificationCode() throws InvalidSPDXAnalysisException {
	Annotation[] annotations = new Annotation[] {ANNOTATION1};
	Relationship[] relationships = new Relationship[] {RELATIONSHIP1};
	Checksum[] checksums = new Checksum[] {CHECKSUM1, CHECKSUM2};
	SpdxFile[] files = new SpdxFile[] {FILE1, FILE2};
	AnyLicenseInfo[] licenseFromFiles = new AnyLicenseInfo[] {LICENSE2};

	SpdxPackage pkg = new SpdxPackage(PKG_NAME1, PKG_COMMENT1, 
			annotations, relationships,	LICENSE1, licenseFromFiles, 
			COPYRIGHT_TEXT1, LICENSE_COMMENT1, LICENSE3, checksums,
			DESCRIPTION1, DOWNLOAD_LOCATION1, files,
			HOMEPAGE1, ORIGINATOR1, PACKAGEFILENAME1, 
			VERIFICATION_CODE1, SOURCEINFO1, SUMMARY1, SUPPLIER1, VERSION1);
	
	assertTrue(VERIFICATION_CODE1.equivalent(pkg.getPackageVerificationCode()));
	Resource r = pkg.createResource(modelContainer);
	assertTrue(VERIFICATION_CODE1.equivalent(pkg.getPackageVerificationCode()));
	SpdxPackage pkg2 = new SpdxPackage(modelContainer, r.asNode());
	assertTrue(VERIFICATION_CODE1.equivalent(pkg2.getPackageVerificationCode()));
	pkg.setPackageVerificationCode(VERIFICATION_CODE2);
	assertTrue(VERIFICATION_CODE2.equivalent(pkg2.getPackageVerificationCode()));
	assertTrue(VERIFICATION_CODE2.equivalent(pkg.getPackageVerificationCode()));
}
 
Example 3
Source Project: RDFUnit   Source File: DqvReportWriter.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public Resource write(Model model) {

    Resource te = null;
    for (QualityMeasure m: measures) {
        te = model.createResource(m.getTestExecutionUri());
        Resource measureResource = model.createResource(JenaUtils.getUniqueIri())
                .addProperty(ResourceFactory.createProperty(DQV_NS + "computedOn"), te)
                .addProperty(ResourceFactory.createProperty(DQV_NS + "hasMetric"), ResourceFactory.createResource(m.getDqvMetricUri()))
                .addProperty(ResourceFactory.createProperty(DQV_NS + "value"), Double.toString(m.getValue()))
                ;

        te.addProperty(ResourceFactory.createProperty(DQV_NS + "dqv:hasQualityMeasure"), measureResource );

    }

    return te;
}
 
Example 4
private <T extends Resource> void extractMapping4MultiSources(Set<Set<String>> cluster,
                                                              Map<String, Set<ResourceWrapper<T>>> m,
                                                              Mapping mappings) {
  Map<T, Set<T>> intermediate2Source = new HashMap<>();
  Map<T, Set<T>> intermediate2Target = new HashMap<>();

  extractIntermediate2SourceTarget(cluster, m, intermediate2Source, intermediate2Target);

  Set<T> intermediate = new HashSet<>();

  intermediate.addAll(intermediate2Source.keySet());
  intermediate.retainAll(intermediate2Target.keySet());

  for (T i : intermediate) {
    Set<T> source = intermediate2Source.get(i);
    Set<T> target = intermediate2Target.get(i);

    for (T s : source) {
      for (T t : target) {
        mappings.add(s, t);
      }
    }
  }
}
 
Example 5
private static final <T extends Resource> void addContextFromSO(Map<ResourceWrapper<T>, Set<SubjectObject>> context,
                                                                ResourceWrapper<T> p,
                                                                Map<Resource, Set<MappingCell>> m,
                                                                Resource subject,
                                                                Resource object) {
  Set<MappingCell> subject_instance_mappings = m.get(subject);
  Set<MappingCell> object_instance_mappings = m.get(object);
  addContextFromSO(context, p, subject_instance_mappings, object_instance_mappings);

  Set<MappingCell> subject_class_mappings = new HashSet<MappingCell>();
  deriveClassMappingsFromResource(subject, m, subject_class_mappings);

  Set<MappingCell> object_class_mappings = new HashSet<MappingCell>();
  deriveClassMappingsFromResource(object, m, object_class_mappings);
  addContextFromSO(context, p, subject_class_mappings, object_class_mappings);
}
 
Example 6
Source Project: tools   Source File: TestSpdxPackage.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Test method for {@link org.spdx.rdfparser.model.SpdxPackage#setLicenseDeclared(org.spdx.rdfparser.license.AnyLicenseInfo)}.
 * @throws InvalidSPDXAnalysisException 
 */
@Test
public void testSetLicenseDeclared() throws InvalidSPDXAnalysisException {
	Annotation[] annotations = new Annotation[] {ANNOTATION1};
	Relationship[] relationships = new Relationship[] {RELATIONSHIP1};
	Checksum[] checksums = new Checksum[] {CHECKSUM1, CHECKSUM2};
	SpdxFile[] files = new SpdxFile[] {FILE1, FILE2};
	AnyLicenseInfo[] licenseFromFiles = new AnyLicenseInfo[] {LICENSE2};

	SpdxPackage pkg = new SpdxPackage(PKG_NAME1, PKG_COMMENT1, 
			annotations, relationships,	LICENSE1, licenseFromFiles, 
			COPYRIGHT_TEXT1, LICENSE_COMMENT1, LICENSE3, checksums,
			DESCRIPTION1, DOWNLOAD_LOCATION1, files,
			HOMEPAGE1, ORIGINATOR1, PACKAGEFILENAME1, 
			VERIFICATION_CODE1, SOURCEINFO1, SUMMARY1, SUPPLIER1, VERSION1);
	
	assertEquals(LICENSE3, pkg.getLicenseDeclared());
	Resource r = pkg.createResource(modelContainer);
	assertEquals(LICENSE3, pkg.getLicenseDeclared());
	SpdxPackage pkg2 = new SpdxPackage(modelContainer, r.asNode());
	assertEquals(LICENSE3, pkg2.getLicenseDeclared());
	pkg.setLicenseDeclared(LICENSE1);
	assertEquals(LICENSE1, pkg.getLicenseDeclared());
	assertEquals(LICENSE1, pkg2.getLicenseDeclared());
}
 
Example 7
Source Project: tools   Source File: TestRdfModelObject.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testAddElementsPropertyValue() throws InvalidSPDXAnalysisException {
	final Model model = ModelFactory.createDefaultModel();
	IModelContainer modelContainer = new ModelContainerForTest(model, "http://testnamespace.com");
	Resource r = model.createResource();
	EmptyRdfModelObject empty = new EmptyRdfModelObject(modelContainer, r.asNode());
	SpdxElement[] result = empty.findMultipleElementPropertyValues(TEST_NAMESPACE, TEST_PROPNAME1);
	assertEquals(0, result.length);
	String elementName1 = "element name 1";
	String elementComment1 = "element comment 1";
	SpdxElement element1 = new SpdxElement(elementName1, elementComment1, null, null);
	empty.addPropertyValue(TEST_NAMESPACE, TEST_PROPNAME1, element1);
	result = empty.findMultipleElementPropertyValues(TEST_NAMESPACE, TEST_PROPNAME1);
	assertEquals(1, result.length);
	assertEquals(element1, result[0]);
	String elementName2 = "element name 2";
	String elementComment2 = "element comment 2";
	SpdxElement element2 = new SpdxElement(elementName2, elementComment2, null, null);
	empty.addPropertyValue(TEST_NAMESPACE, TEST_PROPNAME1, element2);
	result = empty.findMultipleElementPropertyValues(TEST_NAMESPACE, TEST_PROPNAME1);
	assertEquals(2, result.length);
	assertTrue(UnitTestHelper.isArraysEquivalent(new SpdxElement[] {element1,  element2}, result));
}
 
Example 8
Source Project: shacl   Source File: TestCase.java    License: Apache License 2.0 6 votes vote down vote up
public boolean usesDifferentEnvironmentFrom(TestCase other) {
	
	if(getResource().hasProperty(DASH.testModifiesEnvironment)) {
		return true;
	}
	if(other.getResource().hasProperty(DASH.testModifiesEnvironment)) {
		return true;
	}
	
	Resource e1 = getResource().getPropertyResourceValue(DASH.testEnvironment);
	Resource e2 = other.getResource().getPropertyResourceValue(DASH.testEnvironment);
	if(e1 != null && e2 != null) {
		return !e1.equals(e2);
	}
	else if(e1 == null && e2 == null) {
		return false;
	}
	else {
		return true;
	}
}
 
Example 9
Source Project: tools   Source File: TestAnnotation.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Test method for {@link org.spdx.rdfparser.model.Annotation#setAnnotationDate(java.lang.String)}.
 * @throws InvalidSPDXAnalysisException
 */
@Test
public void testSetDate() throws InvalidSPDXAnalysisException {
	Annotation a = new Annotation(ANNOTATOR1, OTHER_ANNOTATION, date, COMMENT1);
	assertEquals(ANNOTATOR1, a.getAnnotator());
	assertEquals(OTHER_ANNOTATION, a.getAnnotationType());
	assertEquals(date, a.getAnnotationDate());
	assertEquals(COMMENT1, a.getComment());
	final Model model = ModelFactory.createDefaultModel();
	IModelContainer modelContainer = new ModelContainerForTest(model, "http://testnamespace.com");
	Resource r = a.createResource(modelContainer);
	a.setAnnotationDate(oldDate);
	assertEquals(oldDate, a.getAnnotationDate());
	Annotation copy = new Annotation(modelContainer, r.asNode());
	assertEquals(oldDate, copy.getAnnotationDate());
}
 
Example 10
Source Project: shacl   Source File: SHACLUtil.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Gets all nodes from a given sh:target.
 * @param target  the value of sh:target (parameterizable or SPARQL target)
 * @param dataset  the dataset to operate on
 * @return an Iterable over the resources
 */
public static Iterable<RDFNode> getResourcesInTarget(Resource target, Dataset dataset) {
	Resource type = JenaUtil.getType(target);
	Resource executable;
	SHParameterizableTarget parameterizableTarget = null;
	if(SHFactory.isParameterizableInstance(target)) {
		executable = type;
		parameterizableTarget = SHFactory.asParameterizableTarget(target);
	}
	else {
		executable = target;
	}
	CustomTargetLanguage plugin = CustomTargets.get().getLanguageForTarget(executable);
	if(plugin != null) {
		Set<RDFNode> results = new HashSet<>();
		plugin.createTarget(executable, parameterizableTarget).addTargetNodes(dataset, results);
		return results;
	}
	else {
		return new ArrayList<>();
	}
}
 
Example 11
Source Project: tools   Source File: SPDXFile.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * @param r1
 * @param r2
 * @return
 */
private boolean resourcesEqual(Resource r1,
		Resource r2) {
	if (r2 == null) {
		return false;
	}
	if (r1.isAnon()) {
		if (!r2.isAnon()) {
			return false;
		}
		return r1.getId().equals(r2.getId());
	} else {
		if (!r2.isURIResource()) {
			return false;
		}
		return r1.getURI().equals(r2.getURI());
	} 
}
 
Example 12
private static Model createModel() {
    Model classModel = ModelFactory.createDefaultModel();
    Resource A = classModel.createResource("http://example.org/A");
    Resource B = classModel.createResource("http://example.org/B");
    Resource C = classModel.createResource("http://example.org/C");
    Resource C2 = classModel.createResource("http://example2.org/C");
    Resource C3 = classModel.createResource("http://example3.org/C");
    Resource D2 = classModel.createResource("http://example2.org/D");
    Resource D3 = classModel.createResource("http://example3.org/D");
    classModel.add(A, RDF.type, RDFS.Class);
    classModel.add(B, RDF.type, RDFS.Class);
    classModel.add(C, RDF.type, RDFS.Class);
    classModel.add(C2, RDF.type, RDFS.Class);
    classModel.add(C3, RDF.type, RDFS.Class);
    classModel.add(D2, RDF.type, RDFS.Class);
    classModel.add(D3, RDF.type, RDFS.Class);
    classModel.add(B, RDFS.subClassOf, A);
    classModel.add(C, RDFS.subClassOf, B);
    classModel.add(C, OWL.sameAs, C2);
    classModel.add(C3, OWL.equivalentClass, C);
    classModel.add(D2, RDFS.subClassOf, C2);
    classModel.add(D3, RDFS.subClassOf, C3);
    return classModel;
}
 
Example 13
Source Project: shacl   Source File: DisjointConstraintExecutor.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void executeConstraint(Constraint constraint, ValidationEngine engine, Collection<RDFNode> focusNodes) {
	long startTime = System.currentTimeMillis();
	Property disjointPredicate = constraint.getParameterValue().as(Property.class);
	for(RDFNode focusNode : focusNodes) {
		if(focusNode instanceof Resource) {
			for(RDFNode valueNode : engine.getValueNodes(constraint, focusNode)) {
				if(((Resource)focusNode).hasProperty(disjointPredicate, valueNode)) {
					engine.createValidationResult(constraint, focusNode, valueNode, () -> "Property must not share any values with " + engine.getLabelFunction().apply(disjointPredicate));
				}
			}
		}
		engine.checkCanceled();
	}
	addStatistics(constraint, startTime);
}
 
Example 14
Source Project: RDFUnit   Source File: TestGeneratorWriter.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public Resource write(Model model) {
    Resource resource = ElementWriter.copyElementResourceInModel(testGenerator, model);

    resource
            .addProperty(RDF.type, RDFUNITv.TestGenerator)
            .addProperty(DCTerms.description, testGenerator.getDescription())
            .addProperty(RDFUNITv.sparqlGenerator, testGenerator.getQuery())
            .addProperty(RDFUNITv.basedOnPattern, ElementWriter.copyElementResourceInModel(testGenerator.getPattern(), model));


    for (ResultAnnotation resultAnnotation: testGenerator.getAnnotations()) {
        Resource annotationResource = ResultAnnotationWriter.create(resultAnnotation).write(model);
        resource.addProperty(RDFUNITv.resultAnnotation, annotationResource);
    }

    return resource;
}
 
Example 15
Source Project: tools   Source File: WithExceptionOperator.java    License: Apache License 2.0 5 votes vote down vote up
protected Resource _createResource(Resource type) throws InvalidSPDXAnalysisException {
	Resource r = model.createResource(type);
	Property licProperty = model.createProperty(SpdxRdfConstants.SPDX_NAMESPACE, SpdxRdfConstants.PROP_LICENSE_SET_MEMEBER);
	Resource licResource = this.license.createResource(this.modelContainer);
	r.addProperty(licProperty, licResource);
	Property exceptionProperty = model.createProperty(SpdxRdfConstants.SPDX_NAMESPACE, SpdxRdfConstants.PROP_LICENSE_EXCEPTION);
	Resource exceptionResource = this.exception.createResource(modelContainer);
	r.addProperty(exceptionProperty, exceptionResource);
	return r;
}
 
Example 16
Source Project: shacl   Source File: SHPropertyShapeImpl.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Property getPredicate() {
	Resource r = getPropertyResourceValue(SH.path);
	if(r != null && r.isURIResource()) {
		return JenaUtil.asProperty(r);
	}
	else {
		return null;
	}
}
 
Example 17
Source Project: tools   Source File: SPDXDocument.java    License: Apache License 2.0 5 votes vote down vote up
private Resource getResource(Node node) throws InvalidSPDXAnalysisException {
	Resource s;
	if (node.isURI()) {
		s = model.createResource(node.getURI());
	} else if (node.isBlank()) {
		s = model.createResource(new AnonId(node.getBlankNodeId()));
	} else {
		throw(new InvalidSPDXAnalysisException("Node can not be a literal"));
	}
	return s;
}
 
Example 18
Source Project: RDFUnit   Source File: TestCaseWriter.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Resource write(Model model) {

    if (testCase instanceof ManualTestCaseImpl) {
        return ManualTestCaseWriter.create((ManualTestCaseImpl) testCase).write(model);
    }

    if (testCase instanceof PatternBasedTestCaseImpl) {
        return PatternBasedTestCaseWriter.create((PatternBasedTestCaseImpl) testCase).write(model);
    }

    throw new UnsupportedOperationException("Writer of test case not implemented: " + testCase.toString());
}
 
Example 19
Source Project: Processor   Source File: ModelExceptionMapper.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Response toResponse(ModelException ex)
{
    Resource exception = toResource(ex, Response.Status.BAD_REQUEST,
        ResourceFactory.createResource("http://www.w3.org/2011/http-statusCodes#BadRequest"));
    ex.getModel().add(exception.getModel());
    
    return getResponseBuilder(DatasetFactory.create(ex.getModel())).status(Response.Status.BAD_REQUEST).build();
}
 
Example 20
Source Project: NLIWOD   Source File: DBpediaIndex.java    License: GNU Affero General Public License v3.0 5 votes vote down vote up
private void addDocumentToIndex(final Resource resource, final String predicate, final String object) throws IOException {
	Document doc = new Document();
	doc.add(new StringField(FIELD_NAME_SUBJECT, resource.getURI(), Store.YES));
	doc.add(new StringField(FIELD_NAME_PREDICATE, predicate, Store.YES));
	doc.add(new TextField(FIELD_NAME_OBJECT, object, Store.YES));
	iwriter.addDocument(doc);
}
 
Example 21
QualifiedValueShapeConstraintExecutor(Constraint constraint) {
	valueShape = constraint.getShapeResource().getPropertyResourceValue(SH.qualifiedValueShape);
	disjoint = constraint.getShapeResource().hasProperty(SH.qualifiedValueShapesDisjoint, JenaDatatypes.TRUE);
	if(disjoint) {
		for(Resource parent : constraint.getShapeResource().getModel().listSubjectsWithProperty(SH.property, constraint.getShapeResource()).toList()) {
			for(Resource ps : JenaUtil.getResourceProperties(parent, SH.property)) {
				siblings.addAll(JenaUtil.getResourceProperties(ps, SH.qualifiedValueShape));
			}
		}
        siblings.remove(valueShape);
	}
	maxCount = JenaUtil.getIntegerProperty(constraint.getShapeResource(), SH.qualifiedMaxCount);
	minCount = JenaUtil.getIntegerProperty(constraint.getShapeResource(), SH.qualifiedMinCount);
}
 
Example 22
private void addHashAnchors(Mapping anchors) {
  if (anchors == null || anchors.isEmpty()) return;

  for (MappingCell c : anchors) {
    Resource r1 = c.getResource1();
    Resource r2 = c.getResource2();

    add(m_resource_to_map_cell, r1, c);
    add(m_resource_to_map_cell, r2, c);
  }
}
 
Example 23
@Override
public <T extends Resource> void matchProperties(Set<T> sources, Set<T> targets, Mapping mappings) {
  Map<ResourceWrapper<T>, Set<SubjectObject>> context = constructContext(sources, targets, m_property_anchors);

  Hermes<ResourceWrapper<T>, SubjectObject> hermes = new Hermes<>();
  hermes.init(context);
  hermes.compute();

  Set<Set<ResourceWrapper<T>>> simplified_extents = null, extents = null;
  if (extract_from_GSH) {
    simplified_extents = extractExtentsFromGSH(hermes);
  }

  if (extract_from_Lattice) {
    extents = extractExtentsFromLattice(hermes);
  }

  if (simplified_extents != null) {
    extractMapping(simplified_extents, mappings);
  }

  if (extents != null) {
    extractMapping(extents, mappings);
  }

  hermes.close();
}
 
Example 24
Source Project: shacl   Source File: AbstractRule.java    License: Apache License 2.0 5 votes vote down vote up
protected AbstractRule(Resource resource) {
	this.resource = resource;
	order = 0;
	Statement s = resource.getProperty(SH.order);
	if(s != null && s.getObject().isLiteral()) {
		order = (Number) s.getLiteral().getValue();
	}
}
 
Example 25
Source Project: tools   Source File: SPDXFile.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * @param seenLicenses the seenLicenses to set
 */
public void setSeenLicenses(SPDXLicenseInfo[] seenLicenses) {
	this.seenLicenses = seenLicenses;
	if (this.model != null && this.node != null) {
		Property p = model.createProperty(SpdxRdfConstants.SPDX_NAMESPACE, SpdxRdfConstants.PROP_FILE_SEEN_LICENSE);
		Resource fileResource = model.createResource(node.getURI());
		model.removeAll(fileResource, p, null);
		p = model.createProperty(SpdxRdfConstants.SPDX_NAMESPACE, SpdxRdfConstants.PROP_FILE_SEEN_LICENSE);

		for (int i = 0; i < seenLicenses.length; i++) {
			Resource lic = seenLicenses[i].createResource(model);
			fileResource.addProperty(p, lic);
		}
	}
}
 
Example 26
Source Project: shacl   Source File: JenaUtil.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Returns a set of resources reachable from a subject via one or more steps with a given predicate.
 * @param subject  the subject to start at
 * @param predicate  the predicate to traverse
 * @return the reached resources
 */
public static Set<Resource> getAllTransitiveObjects(Resource subject, Property predicate) {
	Set<Resource> set = new HashSet<>();
	addTransitiveObjects(set, subject, predicate);
	set.remove(subject);
	return set;
}
 
Example 27
Source Project: tools   Source File: SpdxDocumentContainer.java    License: Apache License 2.0 5 votes vote down vote up
private Resource getResource(Node node) throws InvalidSPDXAnalysisException {
	Resource s;
	if (node.isURI()) {
		s = model.createResource(node.getURI());
	} else if (node.isBlank()) {
		s = model.createResource(new AnonId(node.getBlankNodeId()));
	} else {
		throw(new InvalidSPDXAnalysisException("Node can not be a literal"));
	}
	return s;
}
 
Example 28
Source Project: tools   Source File: TestSpdxPackage.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testSetExternalRefs() throws InvalidSPDXAnalysisException {
	Annotation[] annotations = new Annotation[] {ANNOTATION1};
	Relationship[] relationships = new Relationship[] {RELATIONSHIP1};
	Checksum[] checksums = new Checksum[] {CHECKSUM1, CHECKSUM2};
	SpdxFile[] files = new SpdxFile[] {FILE1, FILE2};
	AnyLicenseInfo[] licenseFromFiles = new AnyLicenseInfo[] {LICENSE2};
	ExternalRef[] externalRefs1 = new ExternalRef[] {EXTERNAL_REF1};
	ExternalRef[] externalRefs2 = new ExternalRef[] {EXTERNAL_REF2, EXTERNAL_REF1};

	SpdxPackage pkg = new SpdxPackage(PKG_NAME1, PKG_COMMENT1, 
			annotations, relationships,	LICENSE1, licenseFromFiles, 
			COPYRIGHT_TEXT1, LICENSE_COMMENT1, LICENSE3, checksums,
			DESCRIPTION1, DOWNLOAD_LOCATION1, files,
			HOMEPAGE1, ORIGINATOR1, PACKAGEFILENAME1, 
			VERIFICATION_CODE1, SOURCEINFO1, SUMMARY1, SUPPLIER1,
			VERSION1, false, externalRefs1);
	
	assertTrue(UnitTestHelper.isArraysEquivalent(externalRefs1, pkg.getExternalRefs()));
	Resource r = pkg.createResource(modelContainer);
	assertTrue(UnitTestHelper.isArraysEquivalent(externalRefs1, pkg.getExternalRefs()));
	SpdxPackage pkg2 = new SpdxPackage(modelContainer, r.asNode());
	assertTrue(UnitTestHelper.isArraysEquivalent(externalRefs1, pkg2.getExternalRefs()));
	pkg.setExternalRefs(externalRefs2);
	assertTrue(UnitTestHelper.isArraysEquivalent(externalRefs2, pkg.getExternalRefs()));
	assertTrue(UnitTestHelper.isArraysEquivalent(externalRefs2, pkg2.getExternalRefs()));
}
 
Example 29
Source Project: shacl   Source File: RuleEngine.java    License: Apache License 2.0 5 votes vote down vote up
private boolean nodeConformsToAllShapes(RDFNode focusNode, Iterable<Resource> shapes) {
	for(Resource shape : shapes) {
		ValidationEngine engine = ValidationEngineFactory.get().create(dataset, shapesGraphURI, shapesGraph, null);
		if(!engine.nodesConformToShape(Collections.singletonList(focusNode), shape.asNode())) {
			return false;
		}
	}
	return true;
}
 
Example 30
Source Project: shacl   Source File: Templates.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Takes an instance of dash:SPARQLConstructTemplate and parameter bindings and returns a Model with the triples
 * that result from the execution of all CONSTRUCT queries in the template using the given parameter bindings.
 * @param template  the template defining the sh:construct queries to run
 * @param bindings  the initial bindings for the CONSTRUCT queries
 * @param dataset  the Dataset to query over
 * @return a Model with the constructed triples
 */
public static Model construct(Resource template, QuerySolutionMap bindings, Dataset dataset) {
	Model result = JenaUtil.createDefaultModel();
	template.listProperties(SH.construct).filterKeep(s -> s.getObject().isLiteral()).forEachRemaining(s -> {			
		String queryString = s.getString();
		Query arqQuery = ARQFactory.get().createQuery(SPARQLSubstitutions.withPrefixes(queryString, template));
		try(QueryExecution qexec = ARQFactory.get().createQueryExecution(arqQuery, dataset, bindings)) {
			qexec.execConstruct(result);
		}
	});
	return result;
}