/** * Checks if a category uri exists in the metadata * * @param categoryType - The URI of the Category Type * @return The URI if exists or null */ private Resource categoryExists(Resource categoryType){ ResIterator resIte = this.metadata.listSubjectsWithProperty(RDF.type, categoryType); if (resIte.hasNext()){ return resIte.next(); } return null; }
// select all resources that are of type Parking ResIterator blockIt = model.listResourcesWithProperty(null, model.getProperty("http://www.w3.org/1999/02/22-rdf-syntax-ns#type"), model.getResource(parkingUri); while (blockIt.hasNext()) { Resource currentParking = blockIt.next(); // select all statements that have the current Parking entity as subject StmtIterator it = model.listStatements(currentParking, null, (RDFNode) null); while (it.hasNext()) { // here you will get all triples for the current Parking block } }
/** * Checks if a dimension uri exists in the metadata * * @param dimensionType - The URI of the Dimension Type * @return The URI if exists or null */ private Resource dimensionExists(Resource dimensionType){ ResIterator resIte = this.metadata.listSubjectsWithProperty(RDF.type, dimensionType); if (resIte.hasNext()){ return resIte.next(); } return null; }
/** * Checks if a metric uri exists in the metadata * * @param metricType - The URI of the Metric Type * @return The URI if exists or null */ private Resource metricExists(Resource metricType){ ResIterator resIte = this.metadata.listSubjectsWithProperty(RDF.type, metricType); if (resIte.hasNext()){ return resIte.next(); } return null; } }
static Set<Resource> subjects(Model model,Property p, RDFNode r) { Set<Resource> subjects = new HashSet<>(); ResIterator it = model.listSubjectsWithProperty(p, r); while(it.hasNext()) subjects.add(it.next().asResource()); it.close(); return subjects; }
private List<Resource> findRoots() { List<Resource> roots = new ArrayList<Resource>(); for (ResIterator i = model.listSubjects(); i.hasNext(); ) { Resource r = i.next(); if (r.isAnon() && model.contains(null, null, r)) continue; roots.add(r); } return roots; }
/** @return The RDF resource which is the root of statements about this page's metadata */ public RDFNodeWrapper pageRoot() { ResIterator i = getModel().listSubjectsWithProperty( RDF.type, API.Page ); if (!i.hasNext()) { throw new EldaException( "Unexpected: page metadata has no resource with rdf:type api:Page" ); } RDFNodeWrapper pageRoot = new RDFNodeWrapper( this, i.next() ); if (i.hasNext()) { log.warn("unexpected: page metadata has more than one rdf:type api:Page resource - {}", i.next()); } return pageRoot; }
private void importRdfModel(Results results, Model model, File baseDir, GraphPropertyWorkData data, VisibilityJson visibilityJson, Visibility visibility, User user, Authorizations authorizations) { ResIterator subjects = model.listSubjects(); while (subjects.hasNext()) { Resource subject = subjects.next(); importSubject(results, graph, subject, baseDir, data, visibilityJson, visibility, user, authorizations); } }
import java.io.ByteArrayInputStream; import com.hp.hpl.jena.rdf.model.Model; import com.hp.hpl.jena.rdf.model.ModelFactory; import com.hp.hpl.jena.rdf.model.ResIterator; import com.hp.hpl.jena.vocabulary.VCARD; public class PropertySubjectsExample { static String CONTENT = "\n" + "@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .\n" + "@prefix vcard: <http://www.w3.org/2001/vcard-rdf/3.0#> .\n" + "@prefix : <http://stackoverflow.com/q/23161586/1281433/>\n" + "\n" + ":x vcard:EMAIL \"visittoravi@gmail.com\"^^xsd:string .\n" + ""; public static void main(String[] args) { Model model = ModelFactory.createDefaultModel(); model.read( new ByteArrayInputStream( CONTENT.getBytes()), null, "TTL" ); ResIterator subjects = model.listSubjectsWithProperty( VCARD.EMAIL, model.createTypedLiteral( "visittoravi@gmail.com" )); while ( subjects.hasNext() ) { System.out.println( subjects.next() ); } } }
/** * @param reference * Unique reference for which the {@link OntClass} is requested * @return {@link OntClass} if there is an already created class for cms object whose identifier got as a * reference, otherwise <code>null</code>. */ public OntClass getOntClassByReference(String reference) throws UnsupportedPolymorphismException, ConversionException { ResIterator it = ontModel.listResourcesWithProperty(CMSAdapterVocabulary.CMSAD_RESOURCE_REF_PROP, reference); Resource resource; if (it.hasNext()) { resource = it.next(); return resource.as(OntClass.class); } return null; }
/** * Gets an {@link DatatypeProperty} for the unique reference specified. * * @param reference * Unique reference for which the {@link DatatypeProperty} is requested. * @return {@link DatatypeProperty} instance if there is a valid one, otherwise <code>null</code>. */ public DatatypeProperty getDatatypePropertyByReference(String reference) throws UnsupportedPolymorphismException, ConversionException { ResIterator it = ontModel.listResourcesWithProperty(CMSAdapterVocabulary.CMSAD_RESOURCE_REF_PROP, reference); Resource resource; if (it.hasNext()) { resource = it.next(); return resource.as(DatatypeProperty.class); } return null; }
/** * Gets an {@link Individual} for the unique reference specified. * * @param reference * Unique reference for which {@link Individual} is requested. * @return {@link Individual} instance if there is a valid one, otherwise <code>null</code> */ public Individual getLooseIndividualByReference(String reference) throws UnsupportedPolymorphismException, ConversionException { ResIterator it = ontModel.listResourcesWithProperty(CMSAdapterVocabulary.CMSAD_RESOURCE_REF_PROP, reference); Resource resource; if (it.hasNext()) { resource = it.next(); return resource.as(Individual.class); } return null; }
protected void loadAnnotations( Set<String> notThese, Set<String> seen, ResIterator ri, boolean isProperty, PrefixMapping prefixes) { while (ri.hasNext()) { Resource res = ri.next(); String uri = res.getURI(); if (uri != null) { String shortForm = null; seen.add( uri ); if (!notThese.contains(uri)) { shortForm = setShortForms( prefixes, res, uri ); } if (isProperty) { if (shortForm == null) shortForm = getLocalName(uri); createPropertyRecord( shortForm, res ); } } } }
/** * Gets an {@link ObjectProperty} for the unique reference specified. * * @param reference * Unique reference for which the {@link ObjectProperty} is requested. * @return {@link ObjectProperty} instance if there is a valid one, otherwise <code>null</code>. */ public ObjectProperty getObjectPropertyByReference(String reference) throws UnsupportedPolymorphismException, ConversionException { ResIterator it = ontModel.listResourcesWithProperty(CMSAdapterVocabulary.CMSAD_RESOURCE_REF_PROP, reference); Resource resource; if (it.hasNext()) { resource = it.next(); return resource.as(ObjectProperty.class); } return null; }
/** * Gets an {@link OntProperty} for the unique reference specified. * * @param reference * Unique reference for which the {@link OntProperty} is requested. * @return {@link OntProperty} instance if there is a valid one, otherwise <code>null</code>. */ public OntProperty getPropertyByReference(String reference) throws UnsupportedPolymorphismException, ConversionException { ResIterator it = ontModel.listResourcesWithProperty(CMSAdapterVocabulary.CMSAD_RESOURCE_REF_PROP, reference); Resource resource; if (it.hasNext()) { resource = it.next(); return resource.as(OntProperty.class); } return null; }
private boolean isMultiplyReferencedbNode(Resource r) { ResIterator ri = model.listSubjectsWithProperty(null, r); boolean multiRef = false; if (ri.hasNext()) { ri.next(); multiRef = ri.hasNext(); } ri.close(); return multiRef; } }
public static Model queryWithAPI() { // Create a model for the output, and add the prefix mappings // from the input model. This step isn't necessary, but it // makes the output easier to read. final Model results = ModelFactory.createDefaultModel(); results.setNsPrefixes( input ); // Iterate through the SocialTags in the data, and for each SocialTag s, retrieve // the statements [s, name, ?name] and [s, importance, ?importance] from the input // model, and add them to the results. for ( final ResIterator it = input.listResourcesWithProperty( RDF.type, SocialTag ); it.hasNext(); ) { final Resource socialTag = it.next(); results.add( socialTag.getProperty( importance )); results.add( socialTag.getProperty( name )); } return results; }
/** * Used when the assessed dataset is stored in memory * (Jena Dataset), * * @param dataset - Assessed Jena Dataset * @param computedOn - The resource indicating the metrics computed on */ public QualityMetadata(Dataset dataset, Resource computedOn){ this.computedOn = computedOn; ResIterator qualityGraphRes = dataset.getDefaultModel().listSubjectsWithProperty(RDF.type, DAQ.QualityGraph); if (qualityGraphRes.hasNext()){ this.qualityGraph = qualityGraphRes.next(); this.metadata.add(dataset.getNamedModel(this.qualityGraph.getURI())); this.metadataPresent = true; } else { this.qualityGraph = Commons.generateURI(); } }
Resource r = itr.next();
public APITester( Model model, ModelLoader loader ) { for (ResIterator ri = model.listSubjectsWithProperty(RDF.type, API.API); ri.hasNext();) { Resource api = ri.next(); APISpec spec = new APISpec( EldaFileManager.get(), api, loader ); specifications.put(api.getLocalName(), spec); for (APIEndpointSpec eps : spec.getEndpoints()) { APIEndpoint ep = APIFactory.makeApiEndpoint(eps); register(ep.getURITemplate(), ep); } } }