org.apache.jena.rdf.model.Property Java Examples
The following examples show how to use
org.apache.jena.rdf.model.Property.
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: SDADatasetAccessor.java From SDA with BSD 2-Clause "Simplified" License | 6 votes |
private static Model makeSampleModel() { String BASE = "http://example/"; Model model = ModelFactory.createDefaultModel(); model.setNsPrefix("", BASE); Resource r1 = model.createResource(BASE + "r1"); Resource r2 = model.createResource(BASE + "r2"); Property p1 = model.createProperty(BASE + "p"); Property p2 = model.createProperty(BASE + "p2"); RDFNode v1 = model.createTypedLiteral("1", XSDDatatype.XSDinteger); RDFNode v2 = model.createTypedLiteral("2", XSDDatatype.XSDinteger); r1.addProperty(p1, v1).addProperty(p1, v2); r1.addProperty(p2, v1).addProperty(p2, v2); r2.addProperty(p1, v1).addProperty(p1, v2); return model; }
Example #2
Source File: SPDXFile.java From tools with Apache License 2.0 | 6 votes |
/** * @param seenLicenses the seenLicenses to set * @throws InvalidSPDXAnalysisException */ public void setSeenLicenses(AnyLicenseInfo[] seenLicenses) throws InvalidSPDXAnalysisException { this.seenLicenses = seenLicenses; if (this.model != null && this.resource != null) { Property p = model.createProperty(SpdxRdfConstants.SPDX_NAMESPACE, SpdxRdfConstants.PROP_FILE_SEEN_LICENSE); model.removeAll(this.resource, p, null); p = model.createProperty(SpdxRdfConstants.SPDX_NAMESPACE, SpdxRdfConstants.PROP_FILE_SEEN_LICENSE); for (int i = 0; i < seenLicenses.length; i++) { Resource lic; try { lic = seenLicenses[i].createResource(this.modelContainer); } catch (DuplicateExtractedLicenseIdException e) { throw(new InvalidSPDXAnalysisException("Seen licenses contains a non-standard license ID "+ " which already exists in the model with different license text:" + seenLicenses[i].toString())); } this.resource.addProperty(p, lic); } } }
Example #3
Source File: RdfModelObject.java From tools with Apache License 2.0 | 6 votes |
/** * Set a property values for this resource. Clears any existing resource. * If the string matches one of the SPDX pre-defined string values, the URI * for that value is stored. Otherwise, it is stored as a literal value. * @param nameSpace RDF Namespace for the property * @param propertyName RDF Property Name (the RDF * @param values Values to associate to this resource */ protected void setPropertyValue(String nameSpace, String propertyName, String[] values) { if (model != null && resource != null) { Property p = model.createProperty(nameSpace, propertyName); model.removeAll(this.resource, p, null); if (values != null) { for (int i = 0; i < values.length; i++) { if (values[i] != null) { String valueUri = PRE_DEFINED_VALUE_URI.get(values[i]); if (valueUri != null) { // this is a pre-defined "special" SPDX value Resource valueResource = this.model.createResource(valueUri); this.resource.addProperty(p, valueResource); } else { this.resource.addLiteral(p, values[i]); } } } } } }
Example #4
Source File: SPDXFile.java From tools with Apache License 2.0 | 6 votes |
/** * Set the file dependencies for this file * @param fileDependencies * @param doc SPDX Document containing the file dependencies * @throws InvalidSPDXAnalysisException */ public void setFileDependencies(SPDXFile[] fileDependencies, SPDXDocument doc) throws InvalidSPDXAnalysisException { if (fileDependencies == null) { this.fileDependencies = new SPDXFile[0]; } else { this.fileDependencies = fileDependencies; } if (this.model != null && this.resource != null) { Property p = model.createProperty(SpdxRdfConstants.SPDX_NAMESPACE, SpdxRdfConstants.PROP_FILE_FILE_DEPENDENCY); model.removeAll(this.resource, p, null); p = model.createProperty(SpdxRdfConstants.SPDX_NAMESPACE, SpdxRdfConstants.PROP_FILE_FILE_DEPENDENCY); for (int i = 0; i < this.fileDependencies.length; i++) { Resource dep = this.fileDependencies[i].getResource(); if (dep == null) { dep = this.fileDependencies[i].createResource(doc, doc.getDocumentNamespace() + doc.getNextSpdxElementRef()); } this.resource.addProperty(p, dep); } } }
Example #5
Source File: EqualsConstraintExecutor.java From shacl with Apache License 2.0 | 6 votes |
@Override public void executeConstraint(Constraint constraint, ValidationEngine engine, Collection<RDFNode> focusNodes) { long startTime = System.currentTimeMillis(); Property equalsPredicate = constraint.getParameterValue().as(Property.class); for(RDFNode focusNode : focusNodes) { if(focusNode instanceof Resource) { Collection<RDFNode> valueNodes = engine.getValueNodes(constraint, focusNode); Set<RDFNode> otherNodes = ((Resource)focusNode).listProperties(equalsPredicate).mapWith(s -> s.getObject()).toSet(); for(RDFNode valueNode : valueNodes) { if(!otherNodes.contains(valueNode)) { engine.createValidationResult(constraint, focusNode, valueNode, () -> "Does not have value at property " + engine.getLabelFunction().apply(equalsPredicate)); } } for(RDFNode otherNode : otherNodes) { if(!valueNodes.contains(otherNode)) { engine.createValidationResult(constraint, focusNode, otherNode, () -> "Expected value from property " + engine.getLabelFunction().apply(equalsPredicate)); } } } engine.checkCanceled(); } addStatistics(constraint, startTime); }
Example #6
Source File: SPDXLicenseSet.java From tools with Apache License 2.0 | 6 votes |
public void setSPDXLicenseInfos(SPDXLicenseInfo[] licenseInfos) { this.licenseInfos.clear(); if (licenseInfos != null) { for (int i = 0; i < licenseInfos.length; i++) { this.licenseInfos.add(licenseInfos[i]); } } if (model != null && licenseInfoNode != null) { // delete any previous created Property licProperty = model.createProperty(SpdxRdfConstants.SPDX_NAMESPACE, SpdxRdfConstants.PROP_LICENSE_SET_MEMEBER); model.removeAll(resource, licProperty, null); licProperty = model.createProperty(SpdxRdfConstants.SPDX_NAMESPACE, SpdxRdfConstants.PROP_LICENSE_SET_MEMEBER); for (int i = 0; i < licenseInfos.length; i++) { Resource licResource = licenseInfos[i].createResource(model); resource.addProperty(licProperty, licResource); } } }
Example #7
Source File: SpdxPackageVerificationCode.java From tools with Apache License 2.0 | 6 votes |
/** * Creates a resource from this SPDX Verification Code * @param model * @return */ public Resource createResource(Model model) { this.model = model; Resource type = model.createResource(SpdxRdfConstants.SPDX_NAMESPACE + SpdxRdfConstants.CLASS_SPDX_VERIFICATIONCODE); Resource r = model.createResource(type); if (this.excludedFileNames.size() > 0) { Property excludedFileProp = model.createProperty(SpdxRdfConstants.SPDX_NAMESPACE, SpdxRdfConstants.PROP_VERIFICATIONCODE_IGNORED_FILES); for (int i = 0; i < this.excludedFileNames.size(); i++) { r.addProperty(excludedFileProp, this.excludedFileNames.get(i)); } } if (this.value != null && !this.value.isEmpty()) { Property valueProperty = model.createProperty(SpdxRdfConstants.SPDX_NAMESPACE, SpdxRdfConstants.PROP_VERIFICATIONCODE_VALUE); r.addProperty(valueProperty, this.value); } this.verificationCodeNode = r.asNode(); this.verificationCodeResource = r; return r; }
Example #8
Source File: RdfModelObject.java From tools with Apache License 2.0 | 6 votes |
/** * Sets a property value as a list of Uris * @param nameSpace * @param propertyName * @param referenceTypeUri * @throws InvalidSPDXAnalysisException */ protected void setPropertyUriValues(String nameSpace, String propertyName, String[] uris) throws InvalidSPDXAnalysisException { if (model != null && resource != null) { Property p = model.createProperty(nameSpace, propertyName); model.removeAll(this.resource, p, null); if (uris != null) { for (int i = 0; i < uris.length; i++) { if (uris[i] != null) { Resource uriResource = model.createResource(uris[i]); this.resource.addProperty(p, uriResource); } } } } }
Example #9
Source File: JenaTransformationRepairSwitchMonitored.java From trainbenchmark with Eclipse Public License 1.0 | 6 votes |
@Override public void activate(final Collection<JenaSwitchMonitoredMatch> matches) throws Exception { final Model model = driver.getModel(); final Property sensorEdge = model.getProperty(BASE_PREFIX + MONITORED_BY); final Resource sensorType = model.getResource(BASE_PREFIX + SENSOR); for (final JenaSwitchMonitoredMatch match : matches) { final Resource sw = match.getSw(); final Long newVertexId = driver.generateNewVertexId(); final Resource sensor = model.createResource(BASE_PREFIX + ID_PREFIX + newVertexId); model.add(model.createStatement(sw, sensorEdge, sensor)); model.add(model.createStatement(sensor, RDF.type, sensorType)); } }
Example #10
Source File: SPDXCreatorInformation.java From tools with Apache License 2.0 | 6 votes |
public Resource createResource(Model model) { this.model = model; Resource type = model.createResource(SpdxRdfConstants.SPDX_NAMESPACE + SpdxRdfConstants.CLASS_SPDX_CREATION_INFO); Resource r = model.createResource(type); if (creators != null && creators.length > 0) { Property nameProperty = model.createProperty(SpdxRdfConstants.SPDX_NAMESPACE, SpdxRdfConstants.PROP_CREATION_CREATOR); for (int i = 0; i < creators.length; i++) { r.addProperty(nameProperty, this.creators[i]); } } if (this.comment != null) { Property commentProperty = model.createProperty(SpdxRdfConstants.RDFS_NAMESPACE, SpdxRdfConstants.RDFS_PROP_COMMENT); r.addProperty(commentProperty, this.comment); } // creation date if (this.createdDate != null) { Property createdDateProperty = model.createProperty(SpdxRdfConstants.SPDX_NAMESPACE, SpdxRdfConstants.PROP_CREATION_CREATED); r.addProperty(createdDateProperty, this.createdDate); } this.creatorNode = r.asNode(); this.creatorResource = r; return r; }
Example #11
Source File: TestPointerFactory.java From tools with Apache License 2.0 | 6 votes |
/** * Test method for {@link org.spdx.rdfparser.model.pointer.PointerFactory#getSinglePointerFromModel(org.spdx.rdfparser.IModelContainer, org.apache.jena.graph.Node)}. * @throws InvalidSPDXAnalysisException */ @Test public void testGetSinglePointerFromModelByProperties() throws InvalidSPDXAnalysisException { int byteOffset = 14; int lineOffset = 1231; SinglePointer bop = new ByteOffsetPointer(REFERENCED1, byteOffset); Resource bopResource = bop.createResource(modelContainer); SinglePointer lcp = new LineCharPointer(REFERENCED2, lineOffset); Resource lcpResource = lcp.createResource(modelContainer); // remove the types Property rdfTypeProperty = modelContainer.getModel().getProperty(SpdxRdfConstants.RDF_NAMESPACE, SpdxRdfConstants.RDF_PROP_TYPE); bopResource.removeAll(rdfTypeProperty); lcpResource.removeAll(rdfTypeProperty); SinglePointer result = PointerFactory.getSinglePointerFromModel(modelContainer, bopResource.asNode()); assertTrue(result instanceof ByteOffsetPointer); assertTrue(REFERENCED1.equivalent(result.getReference())); assertEquals(new Integer(byteOffset), ((ByteOffsetPointer)result).getOffset()); result = PointerFactory.getSinglePointerFromModel(modelContainer, lcpResource.asNode()); assertTrue(result instanceof LineCharPointer); assertTrue(REFERENCED2.equivalent(result.getReference())); assertEquals(new Integer(lineOffset), ((LineCharPointer)result).getLineNumber()); }
Example #12
Source File: JenaUtil.java From shacl with Apache License 2.0 | 6 votes |
private static void addTransitiveSubjects(Set<Resource> reached, Resource object, Property predicate, ProgressMonitor monitor) { if (object != null) { reached.add(object); StmtIterator it = object.getModel().listStatements(null, predicate, object); try { while (it.hasNext()) { if (monitor != null && monitor.isCanceled()) { it.close(); return; } Resource subject = it.next().getSubject(); if (!reached.contains(subject)) { addTransitiveSubjects(reached, subject, predicate, monitor); } } } finally { it.close(); } } }
Example #13
Source File: JenaUtil.java From shacl with Apache License 2.0 | 6 votes |
private static void addTransitiveObjects(Set<Resource> resources, Set<Resource> reached, Resource subject, Property predicate) { resources.add(subject); reached.add(subject); StmtIterator it = subject.listProperties(predicate); try { while (it.hasNext()) { RDFNode object = it.next().getObject(); if (object instanceof Resource) { if (!reached.contains(object)) { addTransitiveObjects(resources, reached, (Resource)object, predicate); } } } } finally { it.close(); } }
Example #14
Source File: SHACLCWriter.java From shacl with Apache License 2.0 | 6 votes |
private void writeExtraStatements(IndentedWriter out, Resource subject, Set<Property> specialProperties, boolean wrapped) { List<Statement> extras = getExtraStatements(subject, specialProperties); if(!extras.isEmpty()) { if(wrapped) { out.print("( "); } for(Statement s : extras) { out.print(" " + getPredicateName(s.getPredicate())); out.print("="); out.print(node(s.getObject())); } if(wrapped) { out.print(" )"); } } }
Example #15
Source File: RDFToTopicMapConverter.java From ontopia with Apache License 2.0 | 6 votes |
/** * Finds all RTM_IN_SCOPE properties for this property and returns a * collection containing the RDF URIs of the values as URILocators. */ private Collection getScope(RDFNode rdfprop, Model model) throws JenaException, MalformedURLException { Resource subject = (Resource) rdfprop; Property prop = model.getProperty(RTM_IN_SCOPE); NodeIterator it = model.listObjectsOfProperty(subject, prop); ArrayList scope = new ArrayList(); while (it.hasNext()) { Object o = it.next(); if (!(o instanceof Resource)) throw new RDFMappingException("Scoping topic must be specified by a resource, not by " + o); Resource obj = (Resource) o; LocatorIF loc = new URILocator(obj.getURI()); scope.add(loc); } return scope; }
Example #16
Source File: SPDXChecksum.java From tools with Apache License 2.0 | 5 votes |
/** * @param value the value to set */ public void setValue(String value) { this.value = value; if (this.model != null && this.checksumNode != null) { // delete any previous value Property p = model.getProperty(SpdxRdfConstants.SPDX_NAMESPACE, SpdxRdfConstants.PROP_CHECKSUM_VALUE); model.removeAll(checksumResource, p, null); // add the property p = model.createProperty(SpdxRdfConstants.SPDX_NAMESPACE, SpdxRdfConstants.PROP_CHECKSUM_VALUE); checksumResource.addProperty(p, value); } }
Example #17
Source File: RdfModelObject.java From tools with Apache License 2.0 | 5 votes |
/** * @param nameSpace * @param propertyName * @param verificationCode * @throws InvalidSPDXAnalysisException */ protected void setPropertyValue(String nameSpace, String propertyName, SpdxPackageVerificationCode verificationCode) throws InvalidSPDXAnalysisException { if (model != null && resource != null) { Property p = model.createProperty(nameSpace, propertyName); model.removeAll(this.resource, p, null); if (verificationCode != null) { this.resource.addProperty(p, verificationCode.createResource(model)); } } }
Example #18
Source File: SPDXDocument.java From tools with Apache License 2.0 | 5 votes |
public void setVerificationCode(SpdxPackageVerificationCode verificationCode) throws InvalidSPDXAnalysisException { removeProperties(node, PROP_PACKAGE_VERIFICATION_CODE); if (verificationCode != null) { Resource verificationCodeResource = verificationCode.createResource(model); Resource s = getResource(this.node); Property p = model.createProperty(SPDX_NAMESPACE, PROP_PACKAGE_VERIFICATION_CODE); s.addProperty(p, verificationCodeResource); } }
Example #19
Source File: LicenseException.java From tools with Apache License 2.0 | 5 votes |
public void setComment(String comment) { this.comment = comment; if (this.exceptionNode != null) { Property commentProperty = model.createProperty(SpdxRdfConstants.RDFS_NAMESPACE, SpdxRdfConstants.RDFS_PROP_COMMENT); model.removeAll(this.resource, commentProperty, null); if (comment != null) { this.resource.addProperty(commentProperty, comment); } } }
Example #20
Source File: RdfModelObject.java From tools with Apache License 2.0 | 5 votes |
/** * Add a checksum as a property to this resource * @param nameSpace * @param propertyName * @param checksumValues * @throws InvalidSPDXAnalysisException */ protected void addPropertyValue(String nameSpace, String propertyName, Checksum checksumValue) throws InvalidSPDXAnalysisException { if (model != null && resource != null) { Property p = model.createProperty(nameSpace, propertyName); if (checksumValue != null) { this.resource.addProperty(p, checksumValue.createResource(this.modelContainer)); } } }
Example #21
Source File: SPDXCreatorInformation.java From tools with Apache License 2.0 | 5 votes |
/** * @param comment the comment to set */ public void setComment(String comment) { this.comment = comment; if (this.creatorNode != null) { // delete any previous comments Property p = model.getProperty(SpdxRdfConstants.RDFS_NAMESPACE, SpdxRdfConstants.RDFS_PROP_COMMENT); model.removeAll(creatorResource, p, null); if (comment != null) { // add the property p = model.createProperty(SpdxRdfConstants.RDFS_NAMESPACE, SpdxRdfConstants.RDFS_PROP_COMMENT); creatorResource.addProperty(p, comment); } } }
Example #22
Source File: JenaUtil.java From shacl with Apache License 2.0 | 5 votes |
/** * Gets an Iterator over all Statements of a given property or its sub-properties * at a given subject instance. Note that the predicate and subject should be * both attached to a Model to avoid NPEs. * @param subject the subject (may be null) * @param predicate the predicate * @return a StmtIterator */ public static StmtIterator listAllProperties(Resource subject, Property predicate) { List<Statement> results = new LinkedList<>(); helper.setGraphReadOptimization(true); try { listAllProperties(subject, predicate, new HashSet<>(), results); } finally { helper.setGraphReadOptimization(false); } return new StmtIteratorImpl(results.iterator()); }
Example #23
Source File: SHACLUtil.java From shacl with Apache License 2.0 | 5 votes |
public static SHPropertyShape getPropertyConstraintAtClass(Resource cls, Property predicate) { for(Resource c : JenaUtil.getAllSuperClassesStar(cls)) { for(Resource arg : JenaUtil.getResourceProperties(c, SH.property)) { if(arg.hasProperty(SH.path, predicate)) { return SHFactory.asPropertyShape(arg); } } } return null; }
Example #24
Source File: SPDXDocument.java From tools with Apache License 2.0 | 5 votes |
/** * @param sha1 the sha1 to set * @throws InvalidSPDXAnalysisException */ public void setSha1(String sha1) throws InvalidSPDXAnalysisException { removeProperties(node, PROP_PACKAGE_CHECKSUM); SPDXChecksum cksum = new SPDXChecksum(SPDXChecksum.ALGORITHM_SHA1, sha1); Resource cksumResource = cksum.createResource(model); Resource s = getResource(this.node); Property p = model.createProperty(SPDX_NAMESPACE, PROP_PACKAGE_CHECKSUM); s.addProperty(p, cksumResource); }
Example #25
Source File: JenaUtil.java From shacl with Apache License 2.0 | 5 votes |
/** * 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 #26
Source File: JenaUtil.java From shacl with Apache License 2.0 | 5 votes |
private static void listAllProperties(Resource subject, Property predicate, Set<Property> reached, List<Statement> results) { reached.add(predicate); StmtIterator sit; Model model; if (subject != null) { sit = subject.listProperties(predicate); model = subject.getModel(); } else { model = predicate.getModel(); sit = model.listStatements(null, predicate, (RDFNode)null); } while (sit.hasNext()) { results.add(sit.next()); } // Iterate into direct subproperties StmtIterator it = model.listStatements(null, RDFS.subPropertyOf, predicate); while (it.hasNext()) { Statement sps = it.next(); if (!reached.contains(sps.getSubject())) { Property subProperty = asProperty(sps.getSubject()); listAllProperties(subject, subProperty, reached, results); } } }
Example #27
Source File: SPDXReview.java From tools with Apache License 2.0 | 5 votes |
/** * @param reviewer the reviewer to set */ @SuppressWarnings("deprecation") public void setReviewer(String reviewer) { this.reviewer = reviewer; if (this.reviewerNode != null && this.model != null) { Property p = model.createProperty(SpdxRdfConstants.SPDX_NAMESPACE, SpdxRdfConstants.PROP_REVIEW_REVIEWER); model.removeAll(this.reviewerResource, p, null); p = model.createProperty(SpdxRdfConstants.SPDX_NAMESPACE, SpdxRdfConstants.PROP_REVIEW_REVIEWER); this.reviewerResource.addProperty(p, reviewer); } }
Example #28
Source File: RdfModelObject.java From tools with Apache License 2.0 | 5 votes |
/** * Set a property value for this resource. Clears any existing resource. * @param nameSpace RDF Namespace for the property * @param propertyName RDF Property Name * @param value Values to set * @throws InvalidSPDXAnalysisException */ protected void setPropertyValue(String nameSpace, String propertyName, StartEndPointer[] values) throws InvalidSPDXAnalysisException { if (model != null && resource != null) { //TODO: Can all of these be replaced by a single method with RdfModel type? Property p = model.createProperty(nameSpace, propertyName); model.removeAll(this.resource, p, null); if (values != null) { for (int i = 0; i < values.length; i++) { this.resource.addProperty(p, values[i].createResource(modelContainer)); } } } }
Example #29
Source File: SHPropertyShapeImpl.java From shacl with Apache License 2.0 | 5 votes |
@Override public String getVarName() { Property argProperty = getPredicate(); if(argProperty != null) { return argProperty.getLocalName(); } else { return null; } }
Example #30
Source File: RdfModelObject.java From tools with Apache License 2.0 | 5 votes |
/** * Sets the spdx element property value for this resource * @param nameSpace * @param propertyName * @param element * @param updateModel If true, update the model from the element. If false, update the * element from the model. This is used for relationships to make sure we don't overwrite * the original element when setting the related element property value. * @throws InvalidSPDXAnalysisException */ protected void setPropertyValue(String nameSpace, String propertyName, SpdxElement[] elements, boolean updateModel) throws InvalidSPDXAnalysisException { if (model != null && resource != null) { Property p = model.createProperty(nameSpace, propertyName); model.removeAll(this.resource, p, null); if (elements != null) { for (int i = 0; i < elements.length; i++) { if (elements[i] != null) { this.resource.addProperty(p, elements[i].createResource(modelContainer, updateModel)); } } } } }