Uploaded image for project: 'Apache Jena'
  1. Apache Jena
  2. JENA-735

Cannot write using TURTLE_FLAT: com.hp.hpl.jena.shared.NoWriterForLangException: TURTLE_FLAT

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • Jena 2.11.2
    • Jena 2.12.0
    • Web site
    • None

    Description

      https://jena.apache.org/documentation/io/rdf-output.html mentioned:

      This page describes the RIOT (RDF I/O technology) output capabilities introduced in Jena 2.10.1. ... There are two ways to write RDF data using Apache Jena RIOT, either via the RDFDataMgr ... or using the model API:

      model.write(output, "format") ;
      

      It should be mentioned in the documentation that using the model API has limited supported formats, and Jena users should use RDFDataMgr because it's typesafe and it supports all formats.

      The Model API (I'm using DefaultModel) method throws exception for TURTLE_FLAT (it works for TURTLE):

      05:14:19.797 [main] DEBUG o.a.j.riot.stream.JenaIOEnvironment - Failed to find configuration: location-mapping.ttl;location-mapping.rdf;location-mapping.n3;etc/location-mapping.rdf;etc/location-mapping.n3;etc/location-mapping.ttl
      05:14:19.851 [main] INFO  c.hendyirawan.wordnet.Wn30CoreToWn31 - Loading WordNet 3.0 core file '/media/ceefour/passport/Tech/Intelligent_Systems/WordNet3/wn30-core-synsets.tab'...
      05:14:19.993 [main] INFO  c.hendyirawan.wordnet.Wn30CoreToWn31 - Converted to 9920 RDF statements
      05:14:19.993 [main] INFO  c.hendyirawan.wordnet.Wn30CoreToWn31 - Saving TURTLE to '/home/ceefour/git/wordnet-extras/wn31-core-synsets.ttl'...
      Exception in thread "main" com.hp.hpl.jena.shared.NoWriterForLangException: TURTLE_FLAT
      	at com.hp.hpl.jena.rdf.model.impl.RDFWriterFImpl.getWriter(RDFWriterFImpl.java:125)
      	at com.hp.hpl.jena.rdf.model.impl.ModelCom.getWriter(ModelCom.java:305)
      	at com.hp.hpl.jena.rdf.model.impl.ModelCom.write(ModelCom.java:354)
      	at com.hendyirawan.wordnet.Wn30CoreToWn31.main(Wn30CoreToWn31.java:96)
      

      Code:

      Model model = ModelFactory.createDefaultModel();
      model.setNsPrefix("wn31", "http://wordnet-rdf.princeton.edu/wn31/");
      model.setNsPrefix("wordnet-ontology", "http://wordnet-rdf.princeton.edu/ontology#");
      model.setNsPrefix("olo", "http://purl.org/ontology/olo/core#");
      Resource synsetRes = model.createResource(model.getNsPrefixURI("wordnet-ontology") + "Synset");
      Property indexProp = model.createProperty(model.getNsPrefixURI("olo"), "index");
      
      File wn30coreFile = new File(args[0]);
      log.info("Loading WordNet 3.0 core file '{}'...", wn30coreFile);
      try (CSVReader reader = new CSVReader(new FileReader(wn30coreFile), '\t')) {
      	int index = 1;
      	while (true) {
      		String[] row = reader.readNext();
      		if (row == null) {
      			break;
      		}
      		String wn30sense = row[0];
      		char posLetter = wn30sense.charAt(9);
      		final Integer posNumeric = Preconditions.checkNotNull(POS_NUMERIC.get(posLetter),
      				"Invalid part-of-speech letter code '%s' for sense '%s'", posLetter, wn30sense);
      		String wn31sense = posNumeric + wn30sense;
      		final Resource wn31res = model.createResource(model.getNsPrefixURI("wn31") + wn31sense);
      		model.add(wn31res, RDF.type, synsetRes);
      		model.addLiteral(wn31res, indexProp, index); // hacky usage, but pragmatic :P
      		index++;
      	}
      }
      
      log.info("Converted to {} RDF statements", Iterators.size(model.listStatements()));
      File wn31TurtleFile = new File(args[1], "wn31-core-synsets.ttl");
      log.info("Saving TURTLE to '{}'...", wn31TurtleFile);
      model.write(new FileOutputStream(wn31TurtleFile), "TURTLE_FLAT");
      

      Attachments

        Activity

          People

            andy Andy Seaborne
            ceefour Hendy Irawan
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: