org.openprovenance.prov.model.Namespace类的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(9.2k)|赞(0)|评价(0)|浏览(141)

本文整理了Java中org.openprovenance.prov.model.Namespace类的一些代码示例,展示了Namespace类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Namespace类的具体详情如下:
包路径:org.openprovenance.prov.model.Namespace
类名称:Namespace

Namespace介绍

[英]A class to manipulate Namespaces when creating, serializing and converting prov documents.
[中]在创建、序列化和转换prov文档时操作名称空间的类。

代码示例

代码示例来源:origin: org.openprovenance.prov/prov-json

private Namespace decodePrefixes(JsonObject bundleStructure) {
Namespace ns = new Namespace();
// prefixes prov and xsd are implicit in prov-json
ns.addKnownNamespaces();
JsonObject prefixes = getObjectAndRemove(bundleStructure,
           PROV_JSON_PREFIX);
if (prefixes != null) {
  for (Map.Entry<String, JsonElement> pair : prefixes.entrySet()) {
  String prefix = pair.getKey();
  String uri = pair.getValue().getAsString();
  if (prefix.equals("default")) {
    ns.registerDefault(uri);
  } else {
    ns.register(prefix, uri);
  }
  }
}
return ns;
}

代码示例来源:origin: org.openprovenance.prov/prov-model

/**
 * @param name the QName to convert to string
 * @param child argument used just for the purpose of debugging when throwing an exception
 * @return a string representation of the QualifiedName
 */
public String qualifiedNameToString(QName name, Namespace child) {
 if ((getDefaultNamespace()!=null) 
   && (getDefaultNamespace().equals(name.getNamespaceURI()))) {
   return name.getLocalPart();
 } else {
   String pref=getNamespaces().get(name.getNamespaceURI());
   if (pref!=null)  {
   return pref + ":" + name.getLocalPart();
   } else {
   if (parent!=null) {
     return parent.qualifiedNameToString(name,this);
   }
   else 
     throw new QualifiedNameException("unknown qualified name " + name 
                     + " with namespace " + toString()
                     + ((child==null)? "" : (" and " + child)));
   }
 }
 }

代码示例来源:origin: lucmoreau/ProvToolbox

public NamespacePrefixMapper(Namespace nss) {
  if (nss!=null) {
    this.defaultNamespace=nss.getDefaultNamespace();
  }
  String xsd_prefix=nss.getNamespaces().get(XSD_NS);
  this.nss=new HashMap<String, String>(nss.getPrefixes()); // don't modify the received map
  this.nss.put(xsd_prefix, DOMProcessing.XSD_NS_FOR_XML);
  
  //System.out.println("PREFIXES IS " + nss);
  //System.out.println("DEFAULT " + defaultNamespace);
}

代码示例来源:origin: org.openprovenance.prov/prov-model

public NamespaceGatherer() {
ns.addKnownNamespaces();
ns.setDefaultNamespace(null);
}

代码示例来源:origin: org.openprovenance.prov/prov-model

public void unregisterDeafult(String namespace) {
String val=getDefaultNamespace();
if (val!=null){
  if (val.equals(namespace)) {
  setDefaultNamespace(null);
  }
}
}

代码示例来源:origin: org.openprovenance.prov/prov-model

public NamespaceGatherer(Hashtable<String, String> prefixes,
             String defaultNamespace) {
ns.getPrefixes().putAll(prefixes);
//TODO create inverse map!
ns.setDefaultNamespace(defaultNamespace);
}

代码示例来源:origin: lucmoreau/ProvToolbox

public void testNamespaces1 () 
{
  Activity a1=pFactory.newActivity(q("a1"));
  Document doc=pFactory.newDocument();
  doc.getStatementOrBundle().add(a1);
  Namespace nss=Namespace.gatherNamespaces(doc);
  //System.out.println("Default ns is: " + nss.getDefaultNamespace());
  //System.out.println("All ns: " + nss.getPrefixes());
  assertNull(nss.getDefaultNamespace());
  assertTrue(nss.getPrefixes().size()==3);
  assertTrue(nss.check("prov", NamespacePrefixMapper.PROV_NS));
  assertTrue(nss.check("ex", EXAMPLE_NS));
  
  assertTrue(nss.check("xsd", NamespacePrefixMapper.XSD_NS));
}

代码示例来源:origin: org.openprovenance.prov/prov-model

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);
}

代码示例来源:origin: org.openprovenance.prov/prov-n

localNamespace.addKnownNamespaces();
  localNamespace.setParent(namespace);
  namespace=localNamespace.getParent();
  return c.newNamedBundle(bundleId,localNamespace,records3);
  String iri1=unwrap(getTokenString(ast.getChild(1)));
  if (pre!=null) { // should not occur
  namespace.register(pre, iri1);
  namespace.registerDefault(iri1);
  return null;

代码示例来源:origin: lucmoreau/ProvToolbox

public void writeDocument(org.openprovenance.prov.model.Document doc,
       String file) {
Namespace.withThreadNamespace(doc.getNamespace());
System.out.println("saving document ... ");
@SuppressWarnings("unused")
Document doc2 = u.persist((org.openprovenance.prov.sql.Document) doc);
dbKeys.put(file, ((org.openprovenance.prov.sql.Document) doc).getPk());
System.out.println("saved document "
  + ((org.openprovenance.prov.sql.Document) doc).getPk()
  + " for " + file);
}

代码示例来源:origin: lucmoreau/ProvToolbox

protected synchronized Namespace initialValue () {
   return new Namespace();
   }
};

代码示例来源:origin: lucmoreau/ProvToolbox

/**
 * 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);
  }
}
}

代码示例来源:origin: org.openprovenance.prov/prov-model

/**
 * Extends this Namespace with all the prefix/namespace registration of the Namespace received as argument. 
 * @param ns the {@link Namespace} whose prefix/namespace registration are added to this {@link Namespace}.
 */
public void extendWith(Namespace ns) {
if (ns==null) return;
if (ns.getDefaultNamespace()!=null) {
  registerDefault(ns.getDefaultNamespace());
}
for (String prefix: ns.prefixes.keySet()) {
  register(prefix, ns.prefixes.get(prefix));
}
}

代码示例来源:origin: org.openprovenance.prov/prov-template

public Document toDocument () {
  
  List<Statement> ll=new LinkedList<Statement>();
  
  add1DValues(ll,variables);  
  add2Dvalues(ll,attributes);
  
  Document dummy=pf.newDocument(null,ll,new LinkedList<Bundle>());
  Document result=pf.newDocument(pf.newNamespace(Namespace.gatherNamespaces(dummy)),ll,new LinkedList<Bundle>());
      
  
  return result;
}

代码示例来源:origin: org.openprovenance.prov/prov-template

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;
}

代码示例来源:origin: org.openprovenance.prov/prov-rdf

protected QualifiedName convertURIToQualifiedName(URI uri) {
QualifiedName qualifiedName;
String uriNamespace = uri.getNamespace();
String prefix=namespace.getNamespaces().get(uriNamespace);
String uriLocalName = qnU.escapeProvLocalName(uri.getLocalName());
if (prefix!=null) {
  qualifiedName = pFactory.newQualifiedName(uriNamespace, uriLocalName, prefix);
} else {
  String defaultNS=namespace.getDefaultNamespace();
  if ((defaultNS!=null) && (defaultNS.equals(uriNamespace))) {
  qualifiedName = pFactory.newQualifiedName(uriNamespace, uriLocalName,null);
  } else {
  namespace.newPrefix(uriNamespace);
  String pref=namespace.getNamespaces().get(uriNamespace);
  qualifiedName = pFactory.newQualifiedName(uriNamespace, uriLocalName, pref);
  }
}    
return qualifiedName;
}

代码示例来源:origin: org.openprovenance.prov/prov-n

private QualifiedName stringToQualifiedName(String attr1) {
return namespace.stringToQualifiedName(attr1,pFactory);
}

代码示例来源:origin: lucmoreau/ProvToolbox

public void addSeed(Document doc, long seed, String name) {
  Namespace namespace = doc.getNamespace();
  QualifiedName qn = namespace.stringToQualifiedName(name, pf);
  for (StatementOrBundle statement : doc.getStatementOrBundle()) {
    if (statement instanceof Identifiable) {
      Identifiable ss = (Identifiable) statement;
      if ((ss.getId() != null) && (ss.getId().equals(qn))) {
        namespace.register(TERM_PREFIX, TERM_NS);
        namespace.addKnownNamespaces();
        ((HasOther) ss).getOther()
            .add(pf.newOther(TERM_NS, "seed", TERM_PREFIX,
                     seed, pf.getName().XSD_LONG));
        return;
      }
    }
  }
}

代码示例来源:origin: lucmoreau/ProvToolbox

public void addKnownNamespaces() {
getPrefixes().put("prov",NamespacePrefixMapper.PROV_NS);
getNamespaces().put(NamespacePrefixMapper.PROV_NS,"prov");
getPrefixes().put("xsd",NamespacePrefixMapper.XSD_NS);
getNamespaces().put(NamespacePrefixMapper.XSD_NS,"xsd");
}

代码示例来源:origin: org.openprovenance.prov/prov-json

id = currentNamespace.stringToQualifiedName(idStr, pf);
Namespace ns = decodePrefixes(attributeMap);
currentNamespace = ns;
currentNamespace.setParent(documentNamespace);
id = currentNamespace.stringToQualifiedName(idStr, pf);
@SuppressWarnings("rawtypes")
Collection statements = decodeBundle(attributeMap);
List<Attribute> attributes = (List<Attribute>) ll;
for (Map.Entry<String, JsonElement> aPair : attributeMap.entrySet()) {
  QualifiedName attributeName = currentNamespace.stringToQualifiedName(aPair.getKey(),pf);
  JsonElement element = aPair.getValue();
  values = pickMultiValues(element);

相关文章