use of org.apache.clerezza.commons.rdf.BlankNode in project stanbol by apache.
the class ClerezzaRDFParser method parse.
@Override
public RDFDataset parse(Object input) throws JsonLdError {
count = 0;
Map<BlankNode, String> bNodeMap = new HashMap<BlankNode, String>(1024);
final RDFDataset result = new RDFDataset();
if (input instanceof Graph) {
for (Triple t : ((Graph) input)) {
handleStatement(result, t, bNodeMap);
}
}
//help gc
bNodeMap.clear();
return result;
}
use of org.apache.clerezza.commons.rdf.BlankNode in project stanbol by apache.
the class IndexedGraphTest method createGraph.
private static void createGraph(Collection<Triple> tc, int triples, Long seed) {
Random rnd = new Random();
if (seed != null) {
rnd.setSeed(seed);
}
LiteralFactory lf = LiteralFactory.getInstance();
//randoms are in the range [0..3]
//literal
double l = 1.0;
//int
double i = l / 3;
//double
double d = l * 2 / 3;
//bNode
double b = 2.0;
//create new bNode
double nb = b - (l * 2 / 3);
double random;
BlankNodeOrIRI subject = null;
IRI predicate = null;
List<IRI> predicateList = new ArrayList<IRI>();
predicateList.add(RDF.first);
predicateList.add(RDF.rest);
predicateList.add(RDF.type);
predicateList.add(RDFS.label);
predicateList.add(RDFS.comment);
predicateList.add(RDFS.range);
predicateList.add(RDFS.domain);
predicateList.add(FOAF.name);
predicateList.add(FOAF.nick);
predicateList.add(FOAF.homepage);
predicateList.add(FOAF.age);
predicateList.add(FOAF.depiction);
String URI_PREFIX = "http://www.test.org/bigGraph/ref";
Language DE = new Language("de");
Language EN = new Language("en");
Iterator<IRI> predicates = predicateList.iterator();
List<BlankNode> bNodes = new ArrayList<BlankNode>();
bNodes.add(new BlankNode());
for (int count = 0; tc.size() < triples; count++) {
random = rnd.nextDouble() * 3;
if (random >= 2.5 || count == 0) {
if (random <= 2.75) {
subject = new IRI(URI_PREFIX + count);
} else {
int rndIndex = (int) ((random - 2.75) * bNodes.size() / (3.0 - 2.75));
subject = bNodes.get(rndIndex);
}
}
if (random > 2.0 || count == 0) {
if (!predicates.hasNext()) {
Collections.shuffle(predicateList, rnd);
predicates = predicateList.iterator();
}
predicate = predicates.next();
}
if (random <= l) {
//literal
if (random <= i) {
tc.add(new TripleImpl(subject, predicate, lf.createTypedLiteral(count)));
} else if (random <= d) {
tc.add(new TripleImpl(subject, predicate, lf.createTypedLiteral(random)));
} else {
Literal text;
if (random <= i) {
text = new PlainLiteralImpl("Literal for " + count);
} else if (random <= d) {
text = new PlainLiteralImpl("An English literal for " + count, EN);
} else {
text = new PlainLiteralImpl("Ein Deutsches Literal für " + count, DE);
}
tc.add(new TripleImpl(subject, predicate, text));
}
} else if (random <= b) {
//bnode
BlankNode bnode;
if (random <= nb) {
bnode = new BlankNode();
bNodes.add(bnode);
} else {
//>nb <b
int rndIndex = (int) ((random - nb) * bNodes.size() / (b - nb));
bnode = bNodes.get(rndIndex);
}
tc.add(new TripleImpl(subject, predicate, bnode));
} else {
//IRI
tc.add(new TripleImpl(subject, predicate, new IRI(URI_PREFIX + count * random)));
}
}
}
use of org.apache.clerezza.commons.rdf.BlankNode in project stanbol by apache.
the class IndexedGraphTest method bNodeConsitency.
@Test
public void bNodeConsitency() {
Graph mGraph = getEmptyGraph();
final BlankNode bNode = new BlankNode() {
@Override
public int hashCode() {
return -1;
}
@Override
public boolean equals(Object o) {
return o instanceof BlankNode;
}
};
final BlankNode bNodeClone = new BlankNode() {
@Override
public int hashCode() {
return -1;
}
@Override
public boolean equals(Object o) {
return o instanceof BlankNode;
}
};
mGraph.add(new TripleImpl(bNode, uriRef1, uriRef2));
mGraph.add(new TripleImpl(bNodeClone, uriRef2, uriRef3));
BlankNodeOrIRI bNodeBack = mGraph.filter(null, uriRef1, uriRef2).next().getSubject();
Assert.assertEquals("The bnode we get back is not equals to the one we added", bNode, bNodeBack);
BlankNodeOrIRI bNodeBack2 = mGraph.filter(null, uriRef2, uriRef3).next().getSubject();
Assert.assertEquals("The returnned bnodes are no longer equals", bNodeBack, bNodeBack2);
Assert.assertTrue("Not finding a triple when searching with equal bNode", mGraph.filter(bNodeBack, uriRef2, null).hasNext());
}
use of org.apache.clerezza.commons.rdf.BlankNode in project stanbol by apache.
the class UserResource method createRole.
/**
* Creates a new role wit the the specified role name
*
* @param newUserName
* @return user node in system graph
*/
private GraphNode createRole(String newRoleName, String comment) {
BlankNode subject = new BlankNode();
GraphNode roleNode = new GraphNode(subject, systemGraph);
roleNode.addProperty(RDF.type, PERMISSION.Role);
roleNode.addProperty(DC.title, new PlainLiteralImpl(newRoleName));
roleNode.addProperty(RDFS.comment, new PlainLiteralImpl(comment));
return roleNode;
}
use of org.apache.clerezza.commons.rdf.BlankNode in project stanbol by apache.
the class UserResource method addPermission.
// public final static String permissionsBase = "urn:x-localhost/role/";
private GraphNode addPermission(GraphNode subjectNode, String permissionString) {
if (hasPermission(subjectNode, permissionString)) {
return subjectNode;
}
GraphNode permissionNode = new GraphNode(new BlankNode(), systemGraph);
permissionNode.addProperty(RDF.type, PERMISSION.Permission);
// permissionNode.addProperty(DC.title, new PlainLiteralImpl(permissionName));
subjectNode.addProperty(PERMISSION.hasPermission, permissionNode.getNode());
permissionNode.addProperty(PERMISSION.javaPermissionEntry, new PlainLiteralImpl(permissionString));
return subjectNode;
}
Aggregations