org.apache.jena.riot.Lang类的使用及代码示例

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

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

Lang介绍

[英]A "language" (syntax). A language has a name, some alternative names, a content type, some alternative content types, and a list of associated file extensions. Names, content types and file extensions must be unique to one language. To create a Lang constant, use LangBuilder and register with RDFLanguages.
[中]一种“语言”(语法)。一种语言有一个名称、一些备选名称、一种内容类型、一些备选内容类型和一个相关文件扩展名列表。名称、内容类型和文件扩展名对于一种语言必须是唯一的。要创建Lang常量,请使用LangBuilder并使用RDFLanguages注册。

代码示例

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

@Override
protected RecordWriter<TKey, QuadWritable> getRecordWriter(Writer writer, Configuration config, Path outputPath)
    throws IOException {
  Lang lang = RDFLanguages.filenameToLang(outputPath.getName());
  if (lang == null)
    throw new IOException("There is no registered RDF language for the output file " + outputPath.toString());
  if (!RDFLanguages.isQuads(lang))
    throw new IOException(
        lang.getName()
            + " is not a RDF quads format, perhaps you wanted TriplesOutputFormat or TriplesOrQuadsOutputFormat instead?");
  // This will throw an appropriate error if the language does not support
  // writing quads
  return HadoopRdfIORegistry.<TKey> createQuadWriter(lang, writer, config);
}

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

/** Remove a registration of a language - this also removes all recorded mapping
 * of content types and file extensions. 
 */

public static void unregister(Lang lang)
{
  if ( lang == null )
    throw new IllegalArgumentException("null for language") ;
  checkRegistration(lang) ; 
  mapLabelToLang.remove(canonicalKey(lang.getLabel())) ;
  mapContentTypeToLang.remove(canonicalKey(lang.getContentType().getContentType())) ;
  
  for ( String ct : lang.getAltContentTypes() )
    mapContentTypeToLang.remove(canonicalKey(ct)) ;
  for ( String ext : lang.getFileExtensions() )
    mapFileExtToLang.remove(canonicalKey(ext)) ;
}

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

private static void checkRegistration(Lang lang)
{
  if ( lang == null )
    return ;
  String label = canonicalKey(lang.getLabel()) ;
  Lang lang2 = mapLabelToLang.get(label) ;
  if ( lang2 == null )
    return ;
  if ( lang.equals(lang2) )
    return ;
  
  // Content type.
  if ( mapContentTypeToLang.containsKey(lang.getContentType().getContentType()))
  {
    String k = lang.getContentType().getContentType() ;
    error("Language overlap: " +lang+" and "+mapContentTypeToLang.get(k)+" on content type "+k) ;
  }
  for (String altName : lang.getAltNames() )
    if ( mapLabelToLang.containsKey(altName) )
      error("Language overlap: " +lang+" and "+mapLabelToLang.get(altName)+" on name "+altName) ;
  for (String ct : lang.getAltContentTypes() )
    if ( mapContentTypeToLang.containsKey(ct) )
      error("Language overlap: " +lang+" and "+mapContentTypeToLang.get(ct)+" on content type "+ct) ;
  for (String ext : lang.getFileExtensions() )
    if ( mapFileExtToLang.containsKey(ext) )
      error("Language overlap: " +lang+" and "+mapFileExtToLang.get(ext)+" on file extension type "+ext) ;
}

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

public String toLongString() { 
    String x = "Lang:" + label + " " + getContentType() ;
    if (getAltNames().size() > 0)
      x = x + " " + getAltNames() ;
    if (getAltContentTypes().size() > 0)
      x = x + " " + getAltContentTypes() ;
    if (getFileExtensions().size() > 0)
      x = x + " " + getFileExtensions() ;

    return x ;
  }
}

代码示例来源:origin: stackoverflow.com

public static void main(String[] args) {
  Lang obj1 = new Lang();
  Lang obj2 = new Lang();

  if (obj1.equals(obj2)) {
    System.out.println("Both Lang objects are equal.");
  }
}

代码示例来源:origin: at.researchstudio.sat/won-matcher-service

public NeedEvent(String uri, String wonNodeUri, TYPE eventType, long crawlDate, String resource, Lang format) {
 this.uri = uri;
 this.wonNodeUri = wonNodeUri;
 this.eventType = eventType;
 this.crawlDate = crawlDate;
 serializedNeedResource = resource;
 serializationLangName = format.getName();
 serializationLangContentType = format.getContentType().getContentType();
}

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

Lang lang = RDFLanguages.contentTypeToLang(mediaType.getContentType()) ;
if ( lang == null )
  lang = RDFLanguages.TRIG ;
              mediaType.getContentType(), mediaType.getCharset(), lang.getName())) ;
if ( !RDFLanguages.isQuads(lang) )
  ServletOps.errorBadRequest("Not a quads format: " + mediaType) ;
try {
  DatasetGraph dsg = decideDataset(action); 
  action.response.setHeader("Content-type", lang.getContentType().toHeaderString());
    RDFDataMgr.write(out, dsg, fmt) ;
  } catch (JenaException ex) {
    if ( fmt.getLang().equals(Lang.RDFXML) )
      ServletOps.errorBadRequest("Failed to write output in RDF/XML: "+ex.getMessage()) ;
    else

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

@Override
  public String toString() {
    if ( variant == null )
      return lang.getName() ;
    return lang.getName() + "/" + variant ;
  }
}

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

@Override
protected RecordWriter<TKey, QuadWritable> getRecordWriter(Writer writer, Configuration config, Path outputPath)
    throws IOException {
  Lang lang = RDFLanguages.filenameToLang(outputPath.getName());
  if (lang == null)
    throw new IOException("There is no registered RDF language for the output file " + outputPath.toString());
  if (!RDFLanguages.isQuads(lang) && !RDFLanguages.isTriples(lang))
    throw new IOException(lang.getName() + " is not a RDF triples/quads format");
  if (HadoopRdfIORegistry.hasQuadWriter(lang)) {
    // Supports quads directly
    return HadoopRdfIORegistry.<TKey> createQuadWriter(lang, writer, config);
  } else {
    // Try to create a triples writer and wrap downwards from quads
    // This will throw an error if a triple writer is not available
    return new QuadsToTriplesWriter<TKey>(HadoopRdfIORegistry.<TKey> createTripleWriter(lang, writer, config));
  }
}

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

@Override
protected RecordWriter<TKey, TripleWritable> getRecordWriter(Writer writer, Configuration config, Path outputPath) throws IOException {
  Lang lang = RDFLanguages.filenameToLang(outputPath.getName());
  if (lang == null)
    throw new IOException("There is no registered RDF language for the output file " + outputPath.toString());
  
  if (!RDFLanguages.isTriples(lang)) throw new IOException(
      lang.getName()
      + " is not a RDF triples format, perhaps you wanted QuadsOutputFormat or TriplesOrQuadsOutputFormat instead?");
  
  // This will throw an appropriate error if the language does not support writing triples
  return HadoopRdfIORegistry.<TKey>createTripleWriter(lang, writer, config);
}

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

protected HttpEntity fileToHttpEntity(String filename, Lang lang) {
  // Leave RDF/XML to the XML parse, else it's UTF-8. 
  String charset = (lang.equals(Lang.RDFXML) ? null : WebContent.charsetUTF8);  
  // HttpClient Content type.
  ContentType ct = ContentType.create(lang.getContentType().getContentType(), charset);
  // Repeatable.
  return new FileEntity(new File(filename), ct);
}

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

public static ContentType guessContentType(String resourceName)
{
  if ( resourceName == null )
    return null ;
  Lang lang = filenameToLang(resourceName) ;
  if ( lang == null )
    return null ;
  return lang.getContentType() ;
}

代码示例来源:origin: AtomGraph/Core

public MediaType(Lang lang)
{
  this(lang.getContentType());
}

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

@Override
    public ResultSetWriter create(Lang lang) {
      lang = Objects.requireNonNull(lang, "Language must not be null");
//            if ( lang.equals(SPARQLResultSetXML) )      return writerXML;
//            if ( lang.equals(SPARQLResultSetJSON) )     return writerJSON;
      if ( lang.equals(SPARQLResultSetCSV) )      return writerCSV;
      if ( lang.equals(SPARQLResultSetTSV) )      return writerTSV;
      if ( lang.equals(SPARQLResultSetText) )     return writerText;
      if ( lang.equals(SPARQLResultSetNone) )     return writerNone;
      throw new RiotException("Lang not registered (ResultSet writer)") ;
    }
  }

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

/** Return our "canonical" name for a Content Type.
 * This should be the standard one, no X-*
 */
public static String contentTypeCanonical(String contentType)
{ 
  Lang lang = RDFLanguages.contentTypeToLang(contentType) ;
  if ( lang == null )
    return null ;
  return lang.getHeaderString() ;
  //return mapLangToContentType.get(lang) ;
}

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

@Override
protected RecordReader<LongWritable, QuadWritable> selectRecordReader(Lang lang) throws IOException {
  if (!RDFLanguages.isQuads(lang) && !RDFLanguages.isTriples(lang))
    throw new IOException(lang.getLabel() + " is not a RDF triples/quads format");
  if (HadoopRdfIORegistry.hasQuadReader(lang)) {
    // Supports quads directly
    return HadoopRdfIORegistry.createQuadReader(lang);
  } else {
    // Try to create a triples reader and wrap upwards into quads
    // This will throw an error if a triple reader is not available
    return new TriplesToQuadsReader(HadoopRdfIORegistry.createTripleReader(lang));
  }
}

代码示例来源:origin: org.aksw.rdfunit/rdfunit-io

public static String getFormatFromExtension(String filename) {
    String format = "TURTLE";
    try {
      // try to get if from Jena first
      String extension;
      Lang jenaLang = RDFLanguages.filenameToLang(filename);
      if (jenaLang != null) {
        extension = jenaLang.getFileExtensions().get(0);
      } else {
        int index = filename.lastIndexOf('.');
        extension = filename.substring(index + 1, filename.length());
      }
      SerializationFormat f = FormatService.getInputFormat(extension);
      if (f != null) {
        format = f.getName();
      }
    } catch (Exception e) {
      log.debug("No format found, using the default one", e);
      return "TURTLE";
    }
    return format;
  }
}

代码示例来源:origin: at.researchstudio.sat/won-bot

private void loadTemplateModel()
{
 logger.info("loading need templateModel model from resource " + this.template);
 Lang lang = RDFLanguages.filenameToLang(this.template.getFilename());
 try {
  this.templateModel = RdfUtils.readRdfSnippet(template.getInputStream(), Lang.TTL.getLabel());
 } catch (IOException e) {
  throw new IllegalArgumentException("Could not read data from resource " + template);
 }
 if (this.templateModel == null){
  logger.warn("reading RDF data from template {} resulted in a null or empty model. Wrapped models will not be modified", this.template);
 }
}

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

@Test
public void testGet()
{
  for (Lang l : RDFLanguages.getRegisteredLanguages() )
  {
    Assert.assertNotNull( l+" can not be parsed by name", RDFLanguages.shortnameToLang( l.getName())  );
  }
}

代码示例来源:origin: at.researchstudio.sat/won-core

private static MediaType[] buildMediaTypeArray(){
 // now register the media types this converter can handle
 Collection<Lang> languages = RDFLanguages.getRegisteredLanguages();
 Set<MediaType> mediaTypeSet = new HashSet<MediaType>();
 for(Lang lang: languages){
  if (datasetWriterExistsForLang(lang)) {
   ContentType ct = lang.getContentType();
   logger.debug("registering converter for rdf content type {}", lang.getContentType());
   MediaType mt = new MediaType(ct.getType(), ct.getSubType());
   mediaTypeSet.add(mt);
  }
 }
 return mediaTypeSet.toArray(new MediaType[mediaTypeSet.size()]);
}

相关文章