org.apache.clerezza.rdf.core.serializedform.Parser类的使用及代码示例

x33g5p2x  于2022-01-26 转载在 其他  
字(13.8k)|赞(0)|评价(0)|浏览(133)

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

Parser介绍

[英]This singleton class provides a method parse to transform serialized RDF forms into ImmutableGraphs. Functionality is delegated to registered ParsingProviders. Such ParsingProviders can be registered and unregistered, later registered ParsingProviders shadow previously registered providers for the same format. Note on synchronization: ParsingProviders must be able to handle concurrent requests.
[中]这个单例类提供了一个方法parse,可以将序列化的RDF表单转换为不可变图。功能委托给注册的ParsingProviders。这样的ParsingProvider可以注册和注销,以后注册的ParsingProvider可以与以前注册的相同格式的提供商进行比较。关于同步的注意事项:ParsingProviders必须能够处理并发请求。

代码示例

代码示例来源:origin: org.apache.clerezza/rdf.core

/**
 * Parses a serialized ImmutableGraph from an InputStream. This delegates the
 * processing to the provider registered for the specified format, if
 * the formatIdentifier contains a ';'-character only the section before
 * that character is used for choosing the provider.
 *
 * @param serializedGraph an inputstream with the serialization
 * @param formatIdentifier a string identifying the format (usually the MIME-type)
 * @return the ImmutableGraph read from the stream
 * @throws UnsupportedFormatException
 */
public ImmutableGraph parse(InputStream serializedGraph,
    String formatIdentifier) throws UnsupportedFormatException {
  return parse(serializedGraph, formatIdentifier, null);
}

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

/**
 * Parses an InputStream of RDF data and produces an Graph from them
 *
 * @param in The InputStream of RDF data
 * @param format the format of the RDF data
 *
 * @return the resulting Graph or null if the RDF serialization format is not supported by the parser
 */
public Graph readModel(InputStream in, String format) {
  Parser parser = Parser.getInstance();
  if (parser.getSupportedFormats().contains(format)) {
    ImmutableGraph graph = parser.parse(in, format);
    Graph model = new SimpleGraph(graph);
    return model;
  } else {
    log.warn("Unsupported RDF format: {}\nSupported RDF formats: {}",
        format, parser.getSupportedFormats());
  }
  return null;
}

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

/**
 * This returns the singleton instance, if an instance has been previously
 * created (e.g. by OSGi declarative services) this instance is returned,
 * otherwise a new instance is created and providers are injected using 
 * the service provider interface (META-INF/services/)
 *
 * @return the singleton Parser instance
 */
public static Parser getInstance() {
  if (instance == null) {
    synchronized (Parser.class) {
      if (instance == null) {
        new Parser();
        Iterator<ParsingProvider> parsingProviders =
            ServiceLoader.load(ParsingProvider.class).iterator();
        while (parsingProviders.hasNext()) {
          ParsingProvider parsingProvider = parsingProviders.next();
          instance.bindParsingProvider(parsingProvider);
        }
        instance.active = true;
        instance.refreshProviderMap();
      }
    }
  }
  return instance;
}

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

public synchronized void extract(String id, Document doc, Map<String, Object> params,
    Graph result)
    throws ExtractorException {
  if (params == null) {
    params = new HashMap<String, Object>();
  }
  params.put(this.uriParameter, id);
  initTransformerParameters(params);
  Source source = new DOMSource(doc);
  ByteArrayOutputStream writer = new ByteArrayOutputStream(8192);
  StreamResult output = new StreamResult(writer);
  try {
    this.transformer.transform(source, output);
    if (LOG.isDebugEnabled()) {
      String rdf = writer.toString("UTF-8");
      LOG.debug(rdf);
    }
    InputStream reader = new ByteArrayInputStream(writer.toByteArray());
    Parser rdfParser = Parser.getInstance();
    ImmutableGraph graph = rdfParser.parse(reader, this.syntax);
    result.addAll(graph);
  } catch (TransformerException e) {
    throw new ExtractorException(e.getMessage(), e);
  } catch (IOException e) {
    throw new ExtractorException(e.getMessage(), e);
  }
}

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

/**
 * Creates a new graph input source by parsing <code>content</code> into a graph created using the
 * supplied {@link TcProvider}, assuming it has the given format.
 * 
 * @param content
 *            the serialized graph content.
 * @param formatIdentifier
 *            the format to parse the content as.
 * @param tcProvider
 *            the provider that will create the graph where the triples will be stored.
 */
public GraphContentInputSource(InputStream content, String formatIdentifier, TcProvider tcProvider) {
  this(content, formatIdentifier, tcProvider, Parser.getInstance());
}

代码示例来源:origin: org.apache.stanbol/org.apache.stanbol.ontologymanager.ontonet

@Override
public String loadInStore(InputStream data, String formatIdentifier, String preferredKey, boolean force) {
  if (data == null) throw new IllegalArgumentException("No data to load ontologies from.");
  // Force is ignored for the content, but the imports?
  // Get sorted list of supported formats, or use specified one.
  Collection<String> formats;
  if (formatIdentifier == null || "".equals(formatIdentifier.trim())) formats = OntologyUtils
      .getPreferredSupportedFormats(parser.getSupportedFormats());
  else formats = Collections.singleton(formatIdentifier);
  // Try each format, return on the first one that was parsed.
  for (String format : formats) {
    try {
      TripleCollection rdfData = parser.parse(data, format);
      return loadInStore(rdfData, preferredKey, force);
    } catch (UnsupportedFormatException e) {
      log.debug("Unsupported format format {}. Trying next one.", format);
      continue;
    } catch (Exception e) {
      log.debug("Parsing format " + format + " failed. Trying next one.", e);
      continue;
    }
  }
  // No parser worked, return null.
  log.error("All parsers failed, giving up.");
  return null;
}

代码示例来源:origin: org.apache.stanbol/org.apache.stanbol.ontologymanager.ontonet

.getPreferredSupportedFormats(parser.getSupportedFormats());
else formats = Collections.singleton(formatIdentifier);
for (String currentFormat : formats) {

代码示例来源:origin: org.apache.clerezza/rdf.core

/**
 * Update providerMap with the providers in the providerList
 *
 */
private void refreshProviderMap() {
  if (active) {
    try {
      final Map<String, ParsingProvider> newProviderMap = new HashMap<String, ParsingProvider>();
      for (ParsingProvider provider : providerList) {
        String[] formatIdentifiers = getFormatIdentifiers(provider);
        for (String formatIdentifier : formatIdentifiers) {
          newProviderMap.put(formatIdentifier, provider);
        }
      }
      providerMap = newProviderMap;
      if (configurationAdmin != null) { //i.e. when we are in an OSGi environment
        Dictionary<String, Object> newConfig = configurationAdmin.getConfiguration(getClass().getName()).getProperties();
        if (newConfig == null) {
          newConfig = new Hashtable<String, Object>();
        }
        Set<String> supportedFormats = getSupportedFormats();
        String[] supportedFromatsArray = supportedFormats.toArray(new String[supportedFormats.size()]);
        newConfig.put(SupportedFormat.supportedFormat, supportedFromatsArray);
        configurationAdmin.getConfiguration(getClass().getName()).update(newConfig);
      }
    } catch (IOException ex) {
      throw new RuntimeException(ex);
    }
  }
}

代码示例来源:origin: org.apache.stanbol/org.apache.stanbol.ontologymanager.ontonet

/**
 * Constructor to be invoked by non-OSGi environments.
 * 
 * @deprecated tcm and wctp are no longer to be supplied directly to the ONManager object. Use
 *             {@link #ONManagerImpl(OntologyProvider, OfflineConfiguration, Dictionary)} instead.
 * 
 * @param tcm
 *            the triple collection manager to be used for storing ontologies.
 * @param wtcp
 *            the triple collection provider to be used for storing ontologies.
 * @param onmconfig
 *            the configuration of this ontology network manager.
 * @param configuration
 *            additional parameters for the ONManager not included in {@link OfflineConfiguration}.
 */
@Deprecated
public ONManagerImpl(TcManager tcm,
           WeightedTcProvider wtcp,
           OfflineConfiguration offline,
           Dictionary<String,Object> configuration) {
  /*
   * Assume this.tcm this.wtcp and this.wtcp were not filled in by OSGi-DS. As a matter of fact,
   * WeightedTcProvider is now ignored as we assume to use those bound with the TcManager.
   */
  this(new ClerezzaOntologyProvider(tcm, offline, new Parser()), offline, configuration);
}

代码示例来源:origin: org.apache.stanbol/org.apache.stanbol.enhancer.engines.htmlextractor

public synchronized void extract(String id, Document doc, Map<String, Object> params,
    Graph result)
    throws ExtractorException {
  if (params == null) {
    params = new HashMap<String, Object>();
  }
  params.put(this.uriParameter, id);
  initTransformerParameters(params);
  Source source = new DOMSource(doc);
  ByteArrayOutputStream writer = new ByteArrayOutputStream(8192);
  StreamResult output = new StreamResult(writer);
  try {
    this.transformer.transform(source, output);
    if (LOG.isDebugEnabled()) {
      String rdf = writer.toString("UTF-8");
      LOG.debug(rdf);
    }
    InputStream reader = new ByteArrayInputStream(writer.toByteArray());
    Parser rdfParser = Parser.getInstance();
    ImmutableGraph graph = rdfParser.parse(reader, this.syntax);
    result.addAll(graph);
  } catch (TransformerException e) {
    throw new ExtractorException(e.getMessage(), e);
  } catch (IOException e) {
    throw new ExtractorException(e.getMessage(), e);
  }
}

代码示例来源:origin: org.apache.stanbol/org.apache.stanbol.ontologymanager.ontonet

/**
 * Creates a new graph input source by parsing <code>content</code> into a graph created using the
 * supplied {@link TcProvider}, assuming it has the given format.
 * 
 * @param content
 *            the serialized graph content.
 * @param formatIdentifier
 *            the format to parse the content as.
 * @param tcProvider
 *            the provider that will create the graph where the triples will be stored.
 */
public GraphContentInputSource(InputStream content, String formatIdentifier, TcProvider tcProvider) {
  this(content, formatIdentifier, tcProvider, Parser.getInstance());
}

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

List<String> supported = OntologyUtils.getPreferredSupportedFormats(parser.getSupportedFormats());
List<String> formats;
if (formatIdentifier == null || "".equals(formatIdentifier.trim())) formats = supported;

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

/**
 * Update providerMap with the providers in the providerList
 *
 */
private void refreshProviderMap() {
  if (active) {
    try {
      final Map<String, ParsingProvider> newProviderMap = new HashMap<String, ParsingProvider>();
      for (ParsingProvider provider : providerList) {
        String[] formatIdentifiers = getFormatIdentifiers(provider);
        for (String formatIdentifier : formatIdentifiers) {
          newProviderMap.put(formatIdentifier, provider);
        }
      }
      providerMap = newProviderMap;
      if (configurationAdmin != null) { //i.e. when we are in an OSGi environment
        Dictionary<String, Object> newConfig = configurationAdmin.getConfiguration(getClass().getName()).getProperties();
        if (newConfig == null) {
          newConfig = new Hashtable<String, Object>();
        }
        Set<String> supportedFormats = getSupportedFormats();
        String[] supportedFromatsArray = supportedFormats.toArray(new String[supportedFormats.size()]);
        newConfig.put(SupportedFormat.supportedFormat, supportedFromatsArray);
        configurationAdmin.getConfiguration(getClass().getName()).update(newConfig);
      }
    } catch (IOException ex) {
      throw new RuntimeException(ex);
    }
  }
}

代码示例来源:origin: org.apache.clerezza/rdf.core

/**
 * Parses a serialized ImmutableGraph from an InputStream. This delegates the
 * processing to the provider registered for the specified format, if
 * the formatIdentifier contains a ';'-character only the section before
 * that character is used for choosing the provider.
 *
 * @param target the Graph to which the parsed triples are added
 * @param serializedGraph an inputstream with the serialization
 * @param formatIdentifier a string identifying the format (usually the MIME-type)
 * @throws UnsupportedFormatException
 */
public void parse(Graph target, InputStream serializedGraph,
    String formatIdentifier) throws UnsupportedFormatException {
  parse(target, serializedGraph, formatIdentifier, null);
}

代码示例来源:origin: fusepoolP3/p3-batchrefine

public static void assertRDFEquals(String actual, String reference,
                    String actualFormat, String referenceFormat) {
    Parser parser = Parser.getInstance();

    boolean equals = parser
        .parse(new ByteArrayInputStream(reference.getBytes()),
            referenceFormat).equals(
            parser.parse(
                new ByteArrayInputStream(actual.getBytes()),
                actualFormat));

    Assert.assertTrue(equals);
  }
}

代码示例来源:origin: org.apache.stanbol/org.apache.stanbol.ontologymanager.ontonet

if (parser == null) parser = Parser.getInstance();
    .getPreferredSupportedFormats(parser.getSupportedFormats());
else formats = Collections.singleton(formatIdentifier);
TripleCollection graph = null;
for (String format : formats) {
  try {
    parser.parse((MGraph) graph, content, format);
    loaded = true;
    break;

代码示例来源:origin: org.apache.stanbol/org.apache.stanbol.ontologymanager.sources.clerezza

/**
 * Creates a new graph input source by parsing <code>content</code> into a graph created using the
 * supplied {@link TcProvider}, assuming it has the given format.
 * 
 * @param content
 *            the serialized graph content.
 * @param formatIdentifier
 *            the format to parse the content as.
 * @param tcProvider
 *            the provider that will create the graph where the triples will be stored.
 */
public GraphContentInputSource(InputStream content, String formatIdentifier, TcProvider tcProvider) {
  this(content, formatIdentifier, tcProvider, Parser.getInstance());
}

代码示例来源:origin: org.apache.stanbol/org.apache.stanbol.ontologymanager.multiplexer.clerezza

List<String> supported = OntologyUtils.getPreferredSupportedFormats(parser.getSupportedFormats());
List<String> formats;
if (formatIdentifier == null || "".equals(formatIdentifier.trim())) formats = supported;

代码示例来源:origin: org.apache.clerezza/rdf.core

/**
 * This returns the singleton instance, if an instance has been previously
 * created (e.g. by OSGi declarative services) this instance is returned,
 * otherwise a new instance is created and providers are injected using 
 * the service provider interface (META-INF/services/)
 *
 * @return the singleton Parser instance
 */
public static Parser getInstance() {
  if (instance == null) {
    synchronized (Parser.class) {
      if (instance == null) {
        new Parser();
        Iterator<ParsingProvider> parsingProviders =
            ServiceLoader.load(ParsingProvider.class).iterator();
        while (parsingProviders.hasNext()) {
          ParsingProvider parsingProvider = parsingProviders.next();
          instance.bindParsingProvider(parsingProvider);
        }
        instance.active = true;
        instance.refreshProviderMap();
      }
    }
  }
  return instance;
}

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

/**
 * Parses a serialized ImmutableGraph from an InputStream. This delegates the
 * processing to the provider registered for the specified format, if
 * the formatIdentifier contains a ';'-character only the section before
 * that character is used for choosing the provider.
 *
 * @param serializedGraph an inputstream with the serialization
 * @param formatIdentifier a string identifying the format (usually the MIME-type)
 * @return the ImmutableGraph read from the stream
 * @throws UnsupportedFormatException
 */
public ImmutableGraph parse(InputStream serializedGraph,
    String formatIdentifier) throws UnsupportedFormatException {
  return parse(serializedGraph, formatIdentifier, null);
}

相关文章

微信公众号

最新文章

更多