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

The following examples show how to use org.apache.jena.rdf.model.Resource. 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: TestSpdxPackage.java    From tools with 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 #2
Source File: TestSpdxPackage.java    From tools with 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 File: DqvReportWriter.java    From RDFUnit with 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
Source File: JenaTransformationRepairPosLength.java    From trainbenchmark with Eclipse Public License 1.0 6 votes vote down vote up
@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 #5
Source File: LexicalMatcherAlphaImpl.java    From FCA-Map with GNU General Public License v3.0 6 votes vote down vote up
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 #6
Source File: DisjointConstraintExecutor.java    From shacl with 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 #7
Source File: AdditionalPropertyMatcherImpl.java    From FCA-Map with GNU General Public License v3.0 6 votes vote down vote up
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 #8
Source File: TestRdfModelObject.java    From tools with 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 #9
Source File: TestCase.java    From shacl with 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 #10
Source File: TestAnnotation.java    From tools with 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 #11
Source File: SimpleSubClassInferencerTest.java    From gerbil with GNU Affero General Public License v3.0 6 votes vote down vote up
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 #12
Source File: TestGeneratorWriter.java    From RDFUnit with 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 #13
Source File: SPDXFile.java    From tools with 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 #14
Source File: SHACLUtil.java    From shacl with 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 #15
Source File: TestLicenseException.java    From tools with Apache License 2.0 5 votes vote down vote up
@Test
public void testSetSeeAlso() throws InvalidSPDXAnalysisException {
	LicenseException le = new LicenseException(EXCEPTION_ID1,
			EXCEPTION_NAME1, EXCEPTION_TEXT1, EXCEPTION_SEEALSO1,
			EXCEPTION_COMMENT1);
	assertEquals(EXCEPTION_ID1, le.getLicenseExceptionId());
	assertEquals(EXCEPTION_NAME1, le.getName());
	assertEquals(EXCEPTION_TEXT1, le.getLicenseExceptionText());
	assertStringsEquals(EXCEPTION_SEEALSO1, le.getSeeAlso());
	assertEquals(EXCEPTION_COMMENT1, le.getComment());
	le.setSeeAlso(EXCEPTION_SEEALSO2);
	assertEquals(EXCEPTION_ID1, le.getLicenseExceptionId());
	assertEquals(EXCEPTION_NAME1, le.getName());
	assertEquals(EXCEPTION_TEXT1, le.getLicenseExceptionText());
	assertStringsEquals(EXCEPTION_SEEALSO2, le.getSeeAlso());
	assertEquals(EXCEPTION_COMMENT1, le.getComment());
	Resource leResource = le.createResource(testContainer);
	LicenseException le2 = new LicenseException(testContainer, leResource.asNode());
	assertEquals(EXCEPTION_ID1, le2.getLicenseExceptionId());
	assertEquals(EXCEPTION_NAME1, le2.getName());
	assertEquals(EXCEPTION_TEXT1, le2.getLicenseExceptionText());
	assertStringsEquals(EXCEPTION_SEEALSO2, le2.getSeeAlso());
	assertEquals(EXCEPTION_COMMENT1, le2.getComment());
	le2.setSeeAlso(EXCEPTION_SEEALSO1);
	assertEquals(EXCEPTION_ID1, le2.getLicenseExceptionId());
	assertEquals(EXCEPTION_NAME1, le2.getName());
	assertEquals(EXCEPTION_TEXT1, le2.getLicenseExceptionText());
	assertStringsEquals(EXCEPTION_SEEALSO1, le2.getSeeAlso());
	assertEquals(EXCEPTION_COMMENT1, le2.getComment());
}
 
Example #16
Source File: HypermediaFilter.java    From Processor with Apache License 2.0 5 votes vote down vote up
public TemplateCall getTemplateCall()
{
    if (!getUriInfo().getMatchedResources().isEmpty() &&
            getUriInfo().getMatchedResources().get(0) instanceof com.atomgraph.server.model.Resource)
        return ((com.atomgraph.server.model.Resource)getUriInfo().getMatchedResources().get(0)).getTemplateCall();
    
    return null;
}
 
Example #17
Source File: Constraint.java    From shacl with Apache License 2.0 5 votes vote down vote up
public Resource getContext() {
	if(shape.getShapeResource().hasProperty(SH.path)) {
		return SH.PropertyShape;
	}
	else {
		return SH.NodeShape;
	}
}
 
Example #18
Source File: JenaUtil.java    From shacl with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a set of resources reachable from an object via one or more reversed steps with a given predicate.
 * @param object  the object to start traversal at
 * @param predicate  the predicate to walk
 * @param monitor  an optional progress monitor to allow cancelation
 * @return the reached resources
 */
public static Set<Resource> getAllTransitiveSubjects(Resource object, Property predicate, ProgressMonitor monitor) {
	Set<Resource> set = new HashSet<>();
	helper.setGraphReadOptimization(true);
	try {
	   addTransitiveSubjects(set, object, predicate, monitor);
	}
	finally {
		helper.setGraphReadOptimization(false);
	}
	set.remove(object);
	return set;
}
 
Example #19
Source File: TestSpdxConstantElement.java    From tools with Apache License 2.0 5 votes vote down vote up
/**
 * Test method for {@link org.spdx.rdfparser.model.SpdxConstantElement#verify()}.
 * @throws InvalidSPDXAnalysisException 
 */
@Test
public void testVerify() throws InvalidSPDXAnalysisException {
	SpdxNoneElement el = new SpdxNoneElement();
	assertEquals(0, el.verify().size());
	Resource res = el.createResource(modelContainer);
	SpdxNoneElement el2 = new SpdxNoneElement(modelContainer, res.asNode());
	assertEquals(0, el2.verify().size());
}
 
Example #20
Source File: ListedExceptions.java    From tools with Apache License 2.0 5 votes vote down vote up
@Override
public Resource createResource(Resource duplicate, String uri,
		Resource type, IRdfModel modelObject) {
	if (duplicate != null) {
		return duplicate;
	} else if (uri == null) {			
		return listedExceptionModel.createResource(getType(listedExceptionModel));
	} else {
		return listedExceptionModel.createResource(uri, getType(listedExceptionModel));
	}
}
 
Example #21
Source File: CypherHandlersIT.java    From rdf2neo with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Loads some basic test RDF data into RDF.
 */
@Before
public void initNeoData () throws IOException
{
	initNeo ();

	try (	
			Driver neoDriver = GraphDatabase.driver( "bolt://127.0.0.1:7687", AuthTokens.basic ( "neo4j", "test" ) );
			RdfDataManager rdfMgr = new RdfDataManager ( RdfDataManagerTest.TDB_PATH );
		)
	{
		CyNodeLoadingHandler handler = new CyNodeLoadingHandler ();
		Neo4jDataManager neoMgr = new Neo4jDataManager ( neoDriver );
		
		// We need the same nodes in all tests
		handler.setRdfDataManager ( rdfMgr );
		handler.setNeo4jDataManager ( neoMgr );
		handler.setLabelsSparql ( RdfDataManagerTest.SPARQL_NODE_LABELS );
		handler.setNodePropsSparql ( RdfDataManagerTest.SPARQL_NODE_PROPS );
		
		Set<Resource> rdfNodes = 
			Stream.of ( iri ( "ex:1" ), iri ( "ex:2" ), iri ( "ex:3" ) )
			.map ( iri -> rdfMgr.getDataSet ().getDefaultModel ().createResource ( iri ) )
			.collect ( Collectors.toSet () );

		handler.accept ( rdfNodes );
	}
}
 
Example #22
Source File: StatementComparator.java    From trainbenchmark with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public int compare(final Statement o1, final Statement o2) {
	final Resource r1 = o1.getObject().asResource();
	final Resource r2 = o2.getObject().asResource();

	return resourceComparator.compare(r1, r2);
}
 
Example #23
Source File: W3CTestRunner.java    From shacl with Apache License 2.0 5 votes vote down vote up
private void collectItems(File manifestFile, String baseURI) throws IOException {
	
	String filePath = manifestFile.getAbsolutePath().replaceAll("\\\\", "/");
	int coreIndex = filePath.indexOf("core/");
	if(coreIndex > 0 && !filePath.contains("sparql/core")) {
		filePath = filePath.substring(coreIndex);
	}
	else {
		int sindex = filePath.indexOf("sparql/");
		if(sindex > 0) {
			filePath = filePath.substring(sindex);
		}
	}
	
	Model model = JenaUtil.createMemoryModel();
	model.read(new FileInputStream(manifestFile), baseURI, FileUtils.langTurtle);
	
	for(Resource manifest : model.listSubjectsWithProperty(RDF.type, MF.Manifest).toList()) {
		for(Resource include : JenaUtil.getResourceProperties(manifest, MF.include)) {
			String path = include.getURI().substring(baseURI.length());
			File includeFile = new File(manifestFile.getParentFile(), path);
			if(path.contains("/")) {
				String addURI = path.substring(0, path.indexOf('/'));
				collectItems(includeFile, baseURI + addURI + "/");
			}
			else {
				collectItems(includeFile, baseURI + path);
			}
		}
		for(Resource entries : JenaUtil.getResourceProperties(manifest, MF.entries)) {
			for(RDFNode entry : entries.as(RDFList.class).iterator().toList()) {
				items.add(new Item(entry.asResource(), filePath, manifestFile));
			}
		}
	}
}
 
Example #24
Source File: ClassesCache.java    From shacl with Apache License 2.0 5 votes vote down vote up
public Predicate<Resource> getPredicate(Resource cls) {
	return predicates.computeIfAbsent(cls, c -> {
		Set<Resource> classes = JenaUtil.getAllSubClassesStar(c);
		if(classes.size() == 1) {
			return new ClassPredicate(c);
		}
		else {
			return new SubClassesPredicate(classes);
		}
	});
}
 
Example #25
Source File: TestLicenseInfoFactory.java    From tools with Apache License 2.0 5 votes vote down vote up
@Override
public Resource createResource(Resource duplicate, String uri,
		Resource type, IRdfModel modelObject) {
	if (duplicate != null) {
		return duplicate;
	} else if (uri == null) {			
		return model.createResource(type);
	} else {
		return model.createResource(uri, type);
	}
}
 
Example #26
Source File: RefinerBase.java    From FCA-Map with GNU General Public License v3.0 5 votes vote down vote up
protected void validateAnchors(Mapping anchors, Mapping refined_mappings) {
  Map<MappingCell, Set<Resource>> context = new HashMap<>();

  for (MappingCell mc : anchors) {
    Set<Resource> attributes = new HashSet<>();
    acquireAttributesFromMappingCell(mc, attributes);
    Set<Resource> inferred_attributes = new HashSet<>(attributes);

    for (Resource a : attributes) {
      Set<Resource> v = m_hash_anchors.get(a);
      if (v != null) {
        inferred_attributes.addAll(v);
      }
    }

    context.put(mc, inferred_attributes);
  }

  Hermes<MappingCell, Resource> hermes = new Hermes<>();
  hermes.init(context);
  hermes.compute();

  Set<MappingCell> enhanced_mappings = extractRefinement(hermes);
  refined_mappings.addAll(enhanced_mappings);

  hermes.close();
}
 
Example #27
Source File: LocationMapperAccept.java    From sparql-generate with Apache License 2.0 5 votes vote down vote up
public void toModel(Model model) {
    for (LookUpRequest s1 : altLocations.keySet()) {
        Resource r = model.createResource();
        Resource e = model.createResource();
        model.add(r, LocationMappingVocab.mapping, e);
        model.add(e, LocationMappingVocab.name, s1.getFilenameOrURI());
        model.add(e, LocationMappingVocab.altName, altLocations.get(s1).getFilenameOrURI());
        model.add(e, accept, s1.getAccept());
    }
}
 
Example #28
Source File: ValidationUtil.java    From shacl with Apache License 2.0 5 votes vote down vote up
/**
 * Validates a given data Model against all shapes from a given shapes Model.
 * If the shapesModel does not include the system graph triples then these will be added.
 * Entailment regimes are applied prior to validation.
 * @param dataModel  the data Model
 * @param shapesModel  the shapes Model
 * @param configuration  configuration for the validation engine
 * @return an instance of sh:ValidationReport in a results Model
 */
public static Resource validateModel(Model dataModel, Model shapesModel, ValidationEngineConfiguration configuration) {

	ValidationEngine engine = createValidationEngine(dataModel, shapesModel, configuration);
	engine.setConfiguration(configuration);
	try {
		engine.applyEntailments();
		return engine.validateAll();
	}
	catch(InterruptedException ex) {
		return null;
	}
}
 
Example #29
Source File: SPDXDocument.java    From tools with Apache License 2.0 5 votes vote down vote up
/**
 * @param reviewers the reviewers to set
 * @throws InvalidSPDXAnalysisException 
 */
public void setReviewers(SPDXReview[] reviewers) throws InvalidSPDXAnalysisException {
	if (reviewers.length > 0) {
		List<String> errors = Lists.newArrayList();
		for (int i = 0;i < reviewers.length; i++) {
			errors.addAll(reviewers[i].verify());
		}
		if (errors.size() > 0) {
			StringBuilder sb = new StringBuilder("Invalid reviewers due to the following errors in validation:\n");
			for (int i = 0; i < errors.size(); i++) {
				sb.append(errors.get(i));
				sb.append('\n');
			}
			throw(new InvalidSPDXAnalysisException(sb.toString()));
		}
	}
	Node spdxDocNode = getSpdxDocNode();
	if (spdxDocNode == null) {
		throw(new InvalidSPDXAnalysisException("Must have an SPDX document to set reviewers"));
	}
	// delete any previous created
	Property p = model.getProperty(SPDX_NAMESPACE, PROP_SPDX_REVIEWED_BY);
	Resource s = getResource(spdxDocNode);
	model.removeAll(s, p, null);
	// add the property
	for (int i = 0; i < reviewers.length; i++) {
		p = model.createProperty(SPDX_NAMESPACE, PROP_SPDX_REVIEWED_BY);
		s.addProperty(p, reviewers[i].createResource(model));
	}
}
 
Example #30
Source File: SHParameterizableInstanceImpl.java    From shacl with Apache License 2.0 5 votes vote down vote up
@Override
public SHParameterizable getParameterizable() {
	Resource type = JenaUtil.getType(this);
	if(type != null) {
		return SHFactory.asParameterizable(type);
	}
	else {
		type = SHACLUtil.getResourceDefaultType(this);
		if(type != null) {
			return SHFactory.asParameterizable(type);
		}
	}
	return null;
}