org.apache.jena.rdf.model.Model.listNameSpaces()方法的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(4.5k)|赞(0)|评价(0)|浏览(126)

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

Model.listNameSpaces介绍

[英](You probably don't want this method; more likely you want the PrefixMapping methods that Model supports.) List the namespaces used by predicates and types in the model. This method is really intended for use by the RDF/XML writer, which needs to know these namespaces to generate correct and vaguely pretty XML.

The namespaces returned are those of (a) every URI used as a property in the model and (b) those of every URI that appears as the object of an rdf:type statement.

Note that the notion of "namespace" used here is not that of an XML prefix-namespace, but just of the minimal legal left part of a URI (see Util.splitNamespace for details). If you want the RDF/XML (or N3) namespaces, treat the Model as a PrefixMapping.
[中](您可能不需要这种方法;更可能需要模型支持的PrefixMapping方法。)列出模型中谓词和类型使用的名称空间。这个方法实际上是供RDF/XML编写器使用的,它需要知道这些名称空间,才能生成正确且模糊漂亮的XML。
返回的名称空间是(a)在模型中用作属性的每个URI的名称空间,以及(b)作为rdf:type语句的对象出现的每个URI的名称空间。
请注意,这里使用的“名称空间”的概念不是XML前缀名称空间,而是URI的最小合法左边部分(有关详细信息,请参阅Util.splitNamespace)。如果需要RDF/XML(或N3)名称空间,请将模型视为前缀映射。

代码示例

代码示例来源:origin: vivo-project/Vitro

@Override
public NsIterator listNameSpaces() {
  return inner.listNameSpaces();
}

代码示例来源:origin: apache/jena

@Override
public NsIterator listNameSpaces() throws ReadDeniedException, AuthenticationRequiredException {
  checkRead();
  return holder.getBaseItem().listNameSpaces();
}

代码示例来源:origin: org.fcrepo/fcrepo-http-commons

/**
 * Filters the map of namespace prefix mappings to just those containing namespace URIs present in the model
 *
 * @param model model
 * @param nsPrefixes map of namespace to uris
 * @return nsPrefixes filtered to namespaces found in the model
 */
private static Map<String, String> filterNamespacesToPresent(final Model model,
    final Map<String, String> nsPrefixes) {
  final Map<String, String> resultNses = new HashMap<>();
  final Set<Entry<String, String>> nsSet = nsPrefixes.entrySet();
  final NsIterator nsIt = model.listNameSpaces();
  while (nsIt.hasNext()) {
    final String ns = nsIt.next();
    final Optional<Entry<String, String>> nsOpt = nsSet.stream()
        .filter(nsEntry -> nsEntry.getValue().equals(ns))
        .findFirst();
    if (nsOpt.isPresent()) {
      final Entry<String, String> nsMatch = nsOpt.get();
      resultNses.put(nsMatch.getKey(), nsMatch.getValue());
    }
  }
  return resultNses;
}

代码示例来源:origin: apache/jena

private void addNameSpaces( Model model )  {
  NsIterator nsIter = model.listNameSpaces();
  while (nsIter.hasNext()) this.addNameSpace( nsIter.nextNs() );
}

代码示例来源:origin: org.apache.jena/jena-core

private void addNameSpaces( Model model )  {
  NsIterator nsIter = model.listNameSpaces();
  while (nsIter.hasNext()) this.addNameSpace( nsIter.nextNs() );
}

代码示例来源:origin: apache/jena

public void testListNamespaces()
{
  fill(model);
  final List<String> L = model.listNameSpaces().toList();
  Assert.assertEquals(TestObjects.numberPredicates, L.size());
  final Set<String> wanted = predicateSet(TestObjects.numberPredicates);
  Assert.assertEquals(wanted, new HashSet<>(L));
}

代码示例来源:origin: org.apache.jena/jena-core

public void testListNamespaces()
{
  fill(model);
  final List<String> L = model.listNameSpaces().toList();
  Assert.assertEquals(TestObjects.numberPredicates, L.size());
  final Set<String> wanted = predicateSet(TestObjects.numberPredicates);
  Assert.assertEquals(wanted, new HashSet<>(L));
}

代码示例来源:origin: apache/jena

public void testNamespaceIterator()
{
  final boolean predf[] = new boolean[num];
  for (int i = 0; i < num; i++)
  {
    predf[i] = false;
  }
  final NsIterator nIter = model.listNameSpaces();
  while (nIter.hasNext())
  {
    final String ns = nIter.nextNs();
    boolean found = false;
    for (int i = 0; i < num; i++)
    {
      if (ns.equals(predicate[i].getNameSpace()))
      {
        found = true;
        Assert.assertFalse("Should not have found " + predicate[i]
            + " already.", predf[i]);
        predf[i] = true;
      }
    }
    Assert.assertTrue("Should have found " + ns, found);
  }
  for (int i = 0; i < num; i++)
  {
    Assert.assertTrue("Should have found " + predicate[i], predf[i]);
  }
}

代码示例来源:origin: org.apache.jena/jena-core

public void testNamespaceIterator()
{
  final boolean predf[] = new boolean[num];
  for (int i = 0; i < num; i++)
  {
    predf[i] = false;
  }
  final NsIterator nIter = model.listNameSpaces();
  while (nIter.hasNext())
  {
    final String ns = nIter.nextNs();
    boolean found = false;
    for (int i = 0; i < num; i++)
    {
      if (ns.equals(predicate[i].getNameSpace()))
      {
        found = true;
        Assert.assertFalse("Should not have found " + predicate[i]
            + " already.", predf[i]);
        predf[i] = true;
      }
    }
    Assert.assertTrue("Should have found " + ns, found);
  }
  for (int i = 0; i < num; i++)
  {
    Assert.assertTrue("Should have found " + predicate[i], predf[i]);
  }
}

相关文章

Model类方法