Refine search
public static AnonId create() { return new AnonId(); }
@Override public Optional<String> asIri() { if (this.rdfNode.isResource()) { Resource resource = rdfNode.asResource(); String uri = resource.getURI(); return uri == null ? Optional.of(resource.getId().getLabelString()) : Optional.of(uri); } else { return Optional.empty(); } }
/** * Test that creation of an AnonId from an AnonId string preserves that * string and is equal to the original AnonId. */ public void testAnonIdPreserved() { final AnonId anon = AnonId.create(); final String id = anon.toString(); Assert.assertEquals(anon, AnonId.create(id)); Assert.assertEquals(id, AnonId.create(id).toString()); }
/** * @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()); } } /**
private String toCell(RDFNode rdfNode) { if( rdfNode == null){ return ""; }else if( rdfNode.isLiteral() ){ return rdfNode.asLiteral().getLexicalForm(); }else if( rdfNode.isResource() ){ Resource resource = (Resource)rdfNode; if( ! resource.isAnon() ){ return resource.getURI(); }else{ return resource.getId().getLabelString(); } }else{ return rdfNode.toString(); } }
throw new IllegalArgumentException("Resource may not be null"); if (resource.isLiteral()) { throw new IllegalArgumentException("Resource may not be a literal"); if (goodResource.getModel() == null) { final Node n = resource.asNode(); if (resource.isAnon()) { goodResource = securedModel.createResource(new AnonId(n.getBlankNodeId())); } else { goodResource = securedModel.createResource(n.getURI());
p.setPickListName(getWebappDaoFactory().makePickListName(p)); if (op.getDomain() != null) p.setDomainVClassURI( (op.getDomain().isAnon()) ? PSEUDO_BNODE_NS+op.getDomain().getId().toString() : op.getDomain().getURI()); if (op.getRange() != null) p.setRangeVClassURI( (op.getRange().isAnon()) ? PSEUDO_BNODE_NS+op.getRange().getId().toString() : op.getRange().getURI() ); OntProperty invOp = null; try { Statement parentStmt = parentStmtIt.nextStatement(); if (parentStmt.getObject().isResource()) { p.setParentURI(((Resource)parentStmt.getObject()).getURI()); RDFNode objectIndividualSortPropertyNode = op.getPropertyValue(PROPERTY_OBJECTINDIVIDUALSORTPROPERTY); if (objectIndividualSortPropertyNode instanceof Resource) { p.setObjectIndividualSortPropertyURI( ((Resource)objectIndividualSortPropertyNode).getURI() ); if( stmt != null && (obj = stmt.getObject()) != null && obj.isURIResource() ){ Resource res = obj.as(Resource.class); if( res != null && res.getURI() != null ){ BaseResourceBean.RoleLevel roleFromModel = BaseResourceBean.RoleLevel.getRoleByUri(res.getURI()); if( roleFromModel != null &&
for (Literal lit : this.getDataPropertyValuesForIndividualByProperty(res.getURI(), datapropURI)) { log.debug("Literal lit = " + lit); DataPropertyStatement ed = new DataPropertyStatementImpl(); getOntModel().enterCriticalSection(Lock.READ); OntResource ontRes = getOntModel().createResource( new AnonId(entity.getLocalName())).as(OntResource.class); if (ontRes == null) { return edList;
public Triple getTriple(){ Resource _sbj, _prd; RDFNode _obj; if (isSubjectBlank) _sbj = ModelFactory.createDefaultModel().createResource(new AnonId(this.subject)); else _sbj = ModelFactory.createDefaultModel().createResource(subject); _prd = ModelFactory.createDefaultModel().createProperty(predicate); if (isObjectBlank) _obj = ModelFactory.createDefaultModel().createResource(new AnonId(this.object)); else if (isObjectLiteral) _obj = ModelFactory.createDefaultModel().createLiteral(object); else _obj = ModelFactory.createDefaultModel().createResource(object); return new Triple(_sbj.asNode(), _prd.asNode(), _obj.asNode()); }
private Statement lgg(Model model, Statement s1, Statement s2) { Resource s = s1.getSubject().equals(s2.getObject()) ? s1.getSubject() : model.createResource(AnonId.create(s1.getSubject().toString() + s2.getSubject().toString())); RDFNode o = s1.getObject().equals(s2.getObject()) ? s1.getObject() : model.createResource(AnonId.create(s1.getObject().toString() + s2.getObject().toString())); return model.createStatement(s, s1.getPredicate(), o); }
? getOntModel().createResource(new AnonId(vclassURI.split("#")[1])) : ResourceFactory.createResource(vclassURI); if (theClass.isAnon() && theClass.canAs(UnionClass.class)) { UnionClass u = theClass.as(UnionClass.class); for (OntClass operand : u.listOperands().toList()) { VClass vc = new VClassJena(operand, getWebappDaoFactory());
this.resource = model.createResource(this.exceptionNode.getURI()); } else if (this.exceptionNode.isBlank()) { this.resource = model.createResource(new AnonId(this.exceptionNode.getBlankNodeId())); SpdxRdfConstants.PROP_LICENSE_EXCEPTION_ID); model.removeAll(this.resource, idProperty, null); this.resource.addProperty(idProperty, this.licenseExceptionId); SpdxRdfConstants.PROP_NAME); model.removeAll(this.resource, nameProperty, null); this.resource.addProperty(nameProperty, this.name); SpdxRdfConstants.RDFS_PROP_COMMENT); model.removeAll(this.resource, commentProperty, null); this.resource.addProperty(commentProperty, this.comment);
@Test public void blankNodes1() { String s = "_:a <http://example/p> 'foo' . " ; StringReader r = new StringReader(s) ; Model m = ModelFactory.createDefaultModel() ; RDFDataMgr.read(m, r, null, RDFLanguages.TURTLE) ; assertEquals(1, m.size()) ; String x = m.listStatements().next().getSubject().getId().getLabelString() ; assertNotEquals(x, "a") ; // reset - reread - new bNode. r = new StringReader(s) ; RDFDataMgr.read(m, r, null, RDFLanguages.TURTLE) ; assertEquals(2, m.size()) ; }
public Individual getIndividualByURI(String entityURI) { if( entityURI == null || entityURI.length() == 0 ) return null; OntModel ontModel = getOntModelSelector().getABoxModel(); ontModel.enterCriticalSection(Lock.READ); try { OntResource ontRes = (entityURI.startsWith(VitroVocabulary.PSEUDO_BNODE_NS)) ? (OntResource) ontModel.createResource(new AnonId(entityURI.substring(VitroVocabulary.PSEUDO_BNODE_NS.length()))).as(OntResource.class) : ontModel.getOntResource(entityURI); Individual ent = new IndividualJena(ontRes, getWebappDaoFactory()); return ent; } catch (Exception ex) { return null; } finally { ontModel.leaveCriticalSection(); } }
protected static String anonName(AnonId id) { String name = "_:A"; String sid = id.toString(); for (int i = 0; i < sid.length(); i++) { char c = sid.charAt(i); if (c == 'X') { name = name + "XX"; } else if (Character.isLetterOrDigit(c)) { name = name + c; } else { name = name + "X" + Integer.toHexString(c) + "X"; } } return name; } }
@Test public void testAddWithBNodes() { final Model model = ModelFactory.createDefaultModel(); final Resource newBNode = ResourceFactory.createResource(AnonId.create().getLabelString()); final int oldSize = _model.getStatements().size(); final List<Statement> statements = Arrays.asList(model.createStatement((Resource) _bNodes[0], _predicates[0], _bNodes[1]), model.createStatement(newBNode, _predicates[0], _bNodes[0]), model.createStatement((Resource) _bNodes[0], _predicates[0], newBNode)); _model.addAllStatementsWithExistingBNodesOnly(statements); assertEquals(oldSize + 3, _model.getStatements().size()); // assertEquals( newBNode, _model.getUniqueObject( // (Resource)_BNodes[0], _predicates[0] ) ); // assertNull( _Model.getUniqueObject( newBNode, predicates[0] ) ); } }
/** * Check that anonIDs are distinct whichever state the flag is in. */ public void doTestAnonID() { final AnonId id1 = AnonId.create(); final AnonId id2 = AnonId.create(); final AnonId id3 = AnonId.create(); final AnonId id4 = AnonId.create(); JenaTestBase.assertDiffer(id1, id2); JenaTestBase.assertDiffer(id1, id3); JenaTestBase.assertDiffer(id1, id4); JenaTestBase.assertDiffer(id2, id3); JenaTestBase.assertDiffer(id2, id4); }