final LinkedHashMap<Item, DataRDFTerm> rdfHash = new LinkedHashMap<Item, DataRDFTerm>();
final LinkedHashSet<Operator> rdfTermToJoin = new LinkedHashSet<Operator>();
for(final GraphWrapper gw : this.visualGraphs.get(0).getBoxes().keySet()) {
if(gw instanceof GraphWrapperOperator) {
final DataRDFTerm rdfTerm = (DataRDFTerm) ((GraphWrapperOperator) gw).getElement();
rdfTermToJoin.add(rdfTerm);
rdfHash.put(rdfTerm.getItem(), rdfTerm);
}
}
try {
final URILiteral rdfURL = LiteralFactory.createURILiteralWithoutLazyLiteral("<inlinedata:" + content + ">");
// first just retrieve the prefixes:
final Reader reader = new InputStreamReader(rdfURL.openStream());
final Map<String, String> prefixMap = JenaTurtleTripleConsumerPipe
.retrievePrefixes(reader);
final HashSet<String> alreadyUsedPrefixes = this.prefix.getPrefixNames();
for (final String prefix : prefixMap.keySet()) {
if(!alreadyUsedPrefixes.contains(prefix)) {
this.prefix.addEntry(prefix, "<" + prefixMap.get(prefix)
+ ">", false);
}
}
// now really get the triples!
CommonCoreQueryEvaluator.readTriples("N3", rdfURL.openStream(), new TripleConsumer() {
public void consume(final Triple triple) {
DataRDFTerm rdfTermSubject = rdfHash.get(triple.getPos(0));
if(rdfTermSubject == null) {
rdfTermSubject = new DataRDFTerm(prefix, triple.getPos(0));
rdfHash.put(triple.getPos(0), rdfTermSubject);
}
DataRDFTerm rdfTermObject = rdfHash.get(triple.getPos(2));
if(rdfTermObject == null) {
rdfTermObject = new DataRDFTerm(prefix, triple.getPos(2));
rdfHash.put(triple.getPos(2), rdfTermObject);
}
rdfTermSubject.addPredicate(rdfTermObject, triple.getPos(1));
final OperatorIDTuple<Operator> opIDT = new OperatorIDTuple<Operator>(rdfTermObject, 0);
if(!rdfTermSubject.getSucceedingOperators().contains(opIDT)) {
rdfTermSubject.addSucceedingOperator(opIDT);
}
rdfTermToJoin.add(rdfTermSubject);
}
});
}
catch(final Exception e) {
System.out.println("Pasted string does not contain N3-data. Trying { (triple pattern)* } (RDF Term)* format!");
try {
final ASTGroupConstraint node = SPARQL1_1Parser.parseN3GroupGraphPatternsAndRDFTerms(content);
for(int i = 0; i < node.jjtGetNumChildren(); i++) {
final Node child = node.jjtGetChild(i);
if(child instanceof ASTGroupConstraint) {
final VisualDataGenerator vdg = new VisualDataGenerator(((VisualGraphOperatorWithPrefix) this.visualGraphs.get(0)).prefix);
rdfTermToJoin.addAll((Collection<Operator>) child.jjtAccept((SPARQL1_1ParserVisitor) vdg, rdfHash));
}
else {
// it is an RDF term!
final Item item = SPARQLCoreParserVisitorImplementation.getItem(child);
DataRDFTerm rdfTerm = rdfHash.get(item);
if(rdfTerm == null) {
rdfTerm = new DataRDFTerm(((VisualGraphOperatorWithPrefix) this.visualGraphs.get(0)).prefix, item);
rdfHash.put(item, rdfTerm);
rdfTermToJoin.add(rdfTerm);
}
}
}