@Override public void doAction(Bundle bun, ProvUtilities provUtilities) { if (flatten) { provUtilities.forAllStatement(bun.getStatement(), this); } else { IndexedDocument iDoc=bundleMap.get(bun.getId()); if (iDoc==null) { iDoc=new IndexedDocument(pFactory, null,flatten); bundleMap.put(bun.getId(),iDoc); } u.forAllStatement(bun.getStatement(), iDoc); } }
public Bundle newNamedBundle(QualifiedName id, Namespace namespace, Collection<Statement> statements) { Bundle res = of.createNamedBundle(); res.setId(id); res.setNamespace(namespace); if (statements != null) { res.getStatement().addAll(statements); } return res; }
public Bundle newNamedBundle(QualifiedName id, Collection<Statement> lks) { Bundle res = of.createNamedBundle(); res.setId(id); if (lks != null) { res.getStatement().addAll(lks); } return res; } public Bundle newNamedBundle(QualifiedName id, Namespace namespace, Collection<Statement> statements) {
@Override public void doAction(Bundle bun, ProvUtilities provUtilities) { bun.setId(uniquify(bun.getId())); provUtilities.forAllStatement(bun.getStatement(), this); }
@SuppressWarnings("unchecked") public List<Statement> getStatement(Bundle d) { List<?> res = d.getStatement(); return (List<Statement>) res; }
public Document toDocument() { Document res=pFactory.newDocument(); List<StatementOrBundle> statementOrBundle = res.getStatementOrBundle(); toContainer(statementOrBundle); if (!flatten) { for (QualifiedName bunId: bundleMap.keySet()) { IndexedDocument idoc=bundleMap.get(bunId); Bundle bun=pFactory.newNamedBundle(bunId, null); List<StatementOrBundle> ll=new LinkedList<StatementOrBundle>(); idoc.toContainer(ll); for (StatementOrBundle s: ll) { bun.getStatement().add((Statement) s); } bun.setNamespace(Namespace.gatherNamespaces(bun)); statementOrBundle.add(bun); } } res.setNamespace(Namespace.gatherNamespaces(res)); return res; } private void toContainer(List<StatementOrBundle> statementOrBundle) {
public Document makePC1GraphAndSpecialization(ProvFactory pFactory) { Document graph = pFactory.newDocument(); String bName = "b123"; // needs to be generated Bundle bun = makePC1FullGraph(pFactory, bName); graph.getStatementOrBundle().add(bun); bun.setNamespace(Namespace.gatherNamespaces(bun)); Hashtable<String, String> namespaces = new Hashtable<String, String>(); // currently, no prefix used, all qnames map to PC1_NS namespaces.put("_", EX_NS); // new default namespace namespaces.put("xsd", NamespacePrefixMapper.XSD_NS); namespaces.put(EX_PREFIX, EX_NS); namespaces.put(DOT_PREFIX, DOT_NS); Entity bunEntity = pFactory.newEntity(bun.getId()); Entity a = pFactory.newEntity(new org.openprovenance.prov.xml.QualifiedName(EX_NS, globalA1.getId().getLocalPart(),null)); MentionOf ctx = pFactory.newMentionOf(a.getId(), globalA1.getId(), bunEntity.getId()); a.getOther().add(pFactory.newOther(DOT_NS, DOT_PREFIX, "color", "blue", name.XSD_STRING)); graph.getStatementOrBundle().add(bunEntity); graph.getStatementOrBundle().add(a); graph.getStatementOrBundle().add(ctx); graph.setNamespace(Namespace.gatherNamespaces(graph)); graph.getNamespace().extendWith(bun.getNamespace()); return graph; }
static public Set<QualifiedName> freeVariables(Bundle statement) { HashSet<QualifiedName> result = new HashSet<QualifiedName>(); QualifiedName name = statement.getId(); if (name != null && isVariable(name)) { result.add(name); } return result; }
public Document expander(Document docIn, Bindings bindings1) { Bundle bun = (Bundle) docIn.getStatementOrBundle().get(0); Groupings grp1 = Groupings.fromDocument(docIn); logger.debug("expander: Found groupings " + grp1); Bundle bun1 = (Bundle) expand(bun, bindings1, grp1).get(0); Document doc1 = pf.newDocument(); doc1.getStatementOrBundle().add(bun1); bun1.setNamespace(Namespace.gatherNamespaces(bun1)); doc1.setNamespace(new Namespace()); return doc1; }
public Bundle doAction(Bundle b, ProvUtilities u) { List<Statement> sRecords = new LinkedList<Statement>(); QualifiedName bundleId=b.getId(); Namespace old=Namespace.getThreadNamespace(); Namespace bundleNamespace; if (b.getNamespace()!=null) { bundleNamespace=new Namespace(b.getNamespace()); } else { bundleNamespace=new Namespace(); } bundleNamespace.setParent(new Namespace(old)); //ensure to make a copy of old, since setting might otherwise create a loop Namespace.withThreadNamespace(bundleNamespace); c.startBundle(bundleId, b.getNamespace()); for (Statement s : u.getStatement(b)) { sRecords.add((Statement) u.doAction(s, this)); } return c.newNamedBundle(bundleId, b.getNamespace(), sRecords); }
/** * After reading a document, this method should be called to ensure that Namespaces are properly chained. * @param document a {@link Document} to update */ public void updateNamespaces(Document document) { Namespace rootNamespace = Namespace.gatherNamespaces(document); document.setNamespace(rootNamespace); for (org.openprovenance.prov.model.Bundle bu: utils.getBundle(document)) { Namespace ns=bu.getNamespace(); if (ns!=null) { ns.setParent(rootNamespace); } else { ns=new Namespace(); ns.setParent(rootNamespace); bu.setNamespace(ns); } } }
/** * Accumulate all namespace declarations in a single {@link Namespace} instance. * This includes the Document-level {@link Namespace} but also all Bundle-level {@link Namespace}s. * * <p>This method is particular useful before serialization to XML since JAXB doesn't offer us the * means to generate prefix declaration in inner Elements. Hence, all namespaces need to be declared * at the root of the xml document. * * @param document Document from which Namespaces are accumulated * @return a new instance of {@link Namespace} */ static public Namespace accumulateAllNamespaces(Document document) { Namespace res=new Namespace(document.getNamespace()); for (Bundle b: pu.getNamedBundle(document)) { Namespace ns=b.getNamespace(); if (ns!=null) res.extendWith(ns); } return res; }
@SuppressWarnings("unchecked") public List<Statement> getStatement(Bundle d) { List<?> res = d.getStatement(); return (List<Statement>) res; }
public Document toDocument() { Document res=pFactory.newDocument(); List<StatementOrBundle> statementOrBundle = res.getStatementOrBundle(); toContainer(statementOrBundle); if (!flatten) { for (QualifiedName bunId: bundleMap.keySet()) { IndexedDocument idoc=bundleMap.get(bunId); Bundle bun=pFactory.newNamedBundle(bunId, null); List<StatementOrBundle> ll=new LinkedList<StatementOrBundle>(); idoc.toContainer(ll); for (StatementOrBundle s: ll) { bun.getStatement().add((Statement) s); } bun.setNamespace(Namespace.gatherNamespaces(bun)); statementOrBundle.add(bun); } } res.setNamespace(Namespace.gatherNamespaces(res)); return res; } private void toContainer(List<StatementOrBundle> statementOrBundle) {
public Bundle newNamedBundle(QualifiedName id, Collection<Statement> lks) { Bundle res = of.createNamedBundle(); res.setId(id); if (lks != null) { res.getStatement().addAll(lks); } return res; } public Bundle newNamedBundle(QualifiedName id, Namespace namespace, Collection<Statement> statements) {
static public Set<QualifiedName> freeVariables(Bundle statement) { HashSet<QualifiedName> result = new HashSet<QualifiedName>(); QualifiedName name = statement.getId(); if (name != null && isVariable(name)) { result.add(name); } return result; }
public Document expander(Document docIn, Bindings bindings1) { Bundle bun = (Bundle) docIn.getStatementOrBundle().get(0); Groupings grp1 = Groupings.fromDocument(docIn); logger.debug("expander: Found groupings " + grp1); Bundle bun1 = (Bundle) expand(bun, bindings1, grp1).get(0); Document doc1 = pf.newDocument(); doc1.getStatementOrBundle().add(bun1); bun1.setNamespace(Namespace.gatherNamespaces(bun1)); doc1.setNamespace(new Namespace()); return doc1; }
public Bundle doAction(Bundle b, ProvUtilities u) { List<Statement> sRecords = new LinkedList<Statement>(); QualifiedName bundleId=b.getId(); Namespace old=Namespace.getThreadNamespace(); Namespace bundleNamespace; if (b.getNamespace()!=null) { bundleNamespace=new Namespace(b.getNamespace()); } else { bundleNamespace=new Namespace(); } bundleNamespace.setParent(new Namespace(old)); //ensure to make a copy of old, since setting might otherwise create a loop Namespace.withThreadNamespace(bundleNamespace); c.startBundle(bundleId, b.getNamespace()); for (Statement s : u.getStatement(b)) { sRecords.add((Statement) u.doAction(s, this)); } return c.newNamedBundle(bundleId, b.getNamespace(), sRecords); }
/** * Accumulate all namespace declarations in a single {@link Namespace} instance. * This includes the Document-level {@link Namespace} but also all Bundle-level {@link Namespace}s. * * <p>This method is particular useful before serialization to XML since JAXB doesn't offer us the * means to generate prefix declaration in inner Elements. Hence, all namespaces need to be declared * at the root of the xml document. * * @param document Document from which Namespaces are accumulated * @return a new instance of {@link Namespace} */ static public Namespace accumulateAllNamespaces(Document document) { Namespace res=new Namespace(document.getNamespace()); for (Bundle b: pu.getNamedBundle(document)) { Namespace ns=b.getNamespace(); if (ns!=null) res.extendWith(ns); } return res; }
@Override public void doAction(Bundle bun, ProvUtilities provUtilities) { if (flatten) { provUtilities.forAllStatement(bun.getStatement(), this); } else { IndexedDocument iDoc=bundleMap.get(bun.getId()); if (iDoc==null) { iDoc=new IndexedDocument(pFactory, null,flatten); bundleMap.put(bun.getId(),iDoc); } u.forAllStatement(bun.getStatement(), iDoc); } }