public List<DataPropertyStatement> getDataPropertyStatements( DataProperty dp, int startIndex, int endIndex) { getOntModel().enterCriticalSection(Lock.READ); List<DataPropertyStatement> dpss = new ArrayList<DataPropertyStatement>(); try { Property prop = ResourceFactory.createProperty(dp.getURI()); ClosableIterator dpsIt = getOntModel().listStatements(null, prop, (Literal) null); try { int count = 0; while ((dpsIt.hasNext()) && ((endIndex < 0) || (count < endIndex))) { ++count; Statement stmt = (Statement) dpsIt.next(); if (startIndex < 0 || startIndex <= count) { Literal lit = (Literal) stmt.getObject(); DataPropertyStatement dps = new DataPropertyStatementImpl(); dps.setDatapropURI(dp.getURI()); dps.setIndividualURI(stmt.getSubject().getURI()); fillDataPropertyStatementWithJenaLiteral(dps, lit); dpss.add(dps); } } } finally { dpsIt.close(); } } finally { getOntModel().leaveCriticalSection(); } return dpss; }
public Individual fillExistingDataPropertyStatementsForIndividual( Individual entity /*, boolean allowAnyNameSpace*/) { if (entity.getURI() == null) { return entity; } else { OntModel ontModel = getOntModelSelector().getABoxModel(); ontModel.enterCriticalSection(Lock.READ); try { Resource ind = ontModel.getResource(entity.getURI()); List<DataPropertyStatement> edList = new ArrayList<DataPropertyStatement>(); StmtIterator stmtIt = ind.listProperties(); while (stmtIt.hasNext()) { Statement st = (Statement) stmtIt.next(); boolean addToList = /*allowAnyNameSpace ? st.getObject().canAs(Literal.class) :*/ st.getObject().isLiteral() && ((RDF.value.equals(st.getPredicate()) || VitroVocabulary.value.equals(st.getPredicate().getURI())) || !(NONUSER_NAMESPACES.contains(st.getPredicate().getNameSpace()))); if (addToList) { /* now want to expose Cornellemailnetid and potentially other properties so can at least control whether visible boolean isExternalId = false; ClosableIterator externalIdStmtIt = getOntModel().listStatements(st.getPredicate(), DATAPROPERTY_ISEXTERNALID, (Literal)null); try { if (externalIdStmtIt.hasNext()) { isExternalId = true; } } finally { externalIdStmtIt.close(); } if (!isExternalId) { */ DataPropertyStatement ed = new DataPropertyStatementImpl(); Literal lit = (Literal) st.getObject(); fillDataPropertyStatementWithJenaLiteral(ed, lit); ed.setDatapropURI(st.getPredicate().getURI()); ed.setIndividualURI(ind.getURI()); ed.setIndividual(entity); edList.add(ed); /* } */ } } entity.setDataPropertyStatements(edList); return entity; } finally { ontModel.leaveCriticalSection(); } } }
public Collection<DataPropertyStatement> getDataPropertyStatementsForIndividualByDataPropertyURI( Individual entity, String datapropURI) { Collection<DataPropertyStatement> edList = new ArrayList<DataPropertyStatement>(); if (entity.getURI() == null) { return edList; } try { getOntModel().enterCriticalSection(Lock.READ); OntResource ontRes = (VitroVocabulary.PSEUDO_BNODE_NS.equals(entity.getNamespace())) ? (OntResource) getOntModel() .createResource(new AnonId(entity.getLocalName())) .as(OntResource.class) : getOntModel().getOntResource(entity.getURI()); if (ontRes == null) { return edList; } ClosableIterator stmtIt; stmtIt = (datapropURI != null) ? ontRes.listProperties(getOntModel().getProperty(datapropURI)) : ontRes.listProperties(); try { while (stmtIt.hasNext()) { Statement st = (Statement) stmtIt.next(); if (st.getObject().isLiteral()) { DataPropertyStatement ed = new DataPropertyStatementImpl(); Literal lit = (Literal) st.getObject(); fillDataPropertyStatementWithJenaLiteral(ed, lit); ed.setIndividualURI(entity.getURI()); ed.setIndividual(entity); ed.setDatapropURI(st.getPredicate().getURI()); edList.add(ed); } } } finally { stmtIt.close(); } } finally { getOntModel().leaveCriticalSection(); } return edList; }