Skip to content

TurtleDocumentFormat: can't parse PREFIX #1149

@sszuev

Description

@sszuev

PREFIX is a modern alternative for @prefix: https://www.w3.org/TR/turtle/#turtle-prefixes

following testcase fails with exception:

        String ttl = """
                PREFIX dc:   <http://purl.org/dc/elements/1.1/>
                PREFIX owl:  <http://www.w3.org/2002/07/owl#>
                PREFIX rdf:  <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
                PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
                PREFIX xsd:  <http://www.w3.org/2001/XMLSchema#>
                """;
        OWLOntology owl = OntManagers.createOWLAPIImplManager().loadOntologyFromOntologyDocument(
                new StringDocumentSource(ttl, IRI.create("x"), new TurtleDocumentFormat(), "ttl")
        );
        owl.saveOntology(System.out);
Exception in thread "main" org.semanticweb.owlapi.io.UnparsableOntologyException: Problem parsing x
Could not parse ontology.  Either a suitable parser could not be found, or parsing failed.  See parser logs below for explanation.
The following parsers were tried:
1) org.semanticweb.owlapi.rdf.turtle.parser.TurtleOntologyParser@724f138e


Detailed logs:
--------------------------------------------------------------------------------
Parser: org.semanticweb.owlapi.rdf.turtle.parser.TurtleOntologyParser@724f138e
    Stack trace:
org.semanticweb.owlapi.rdf.turtle.parser.ParseException: Encountered unexpected token: "PREFIX" <PN_LOCAL>
    at line 1, column 1.

Was expecting one of:

    "("
    "@base"
    "@prefix"
    "["
    <EMPTY_BLANK_NODE>
    <FULLIRI>
    <NODEID>
    <PNAME_LN>
    <PNAME_NS>
        org.semanticweb.owlapi.rdf.turtle.parser.TurtleOntologyParser.parse(TurtleOntologyParser.java:58)
        uk.ac.manchester.cs.owl.owlapi.OWLOntologyFactoryImpl.loadOWLOntology(OWLOntologyFactoryImpl.java:195)
        uk.ac.manchester.cs.owl.owlapi.OWLOntologyManagerImpl.load(OWLOntologyManagerImpl.java:1105)
        uk.ac.manchester.cs.owl.owlapi.OWLOntologyManagerImpl.loadOntology(OWLOntologyManagerImpl.java:1055)
        uk.ac.manchester.cs.owl.owlapi.OWLOntologyManagerImpl.loadOntologyFromOntologyDocument(OWLOntologyManagerImpl.java:1005)
        com.github.owlcs.ontapi.tmp.TmpTurtleInvestigation.main(TmpTurtleInvestigation.java:25)
Encountered unexpected token: "PREFIX" <PN_LOCAL>
    at line 1, column 1.

Was expecting one of:

    "("
    "@base"
    "@prefix"
    "["
    <EMPTY_BLANK_NODE>
    <FULLIRI>
    <NODEID>
    <PNAME_LN>
    <PNAME_NS>
        org.semanticweb.owlapi.rdf.turtle.parser.TurtleParser.generateParseException(TurtleParser.java:1034)
        org.semanticweb.owlapi.rdf.turtle.parser.TurtleParser.jj_consume_token(TurtleParser.java:902)
        org.semanticweb.owlapi.rdf.turtle.parser.TurtleParser.parseDocument(TurtleParser.java:165)
        org.semanticweb.owlapi.rdf.turtle.parser.TurtleOntologyParser.parse(TurtleOntologyParser.java:54)
        uk.ac.manchester.cs.owl.owlapi.OWLOntologyFactoryImpl.loadOWLOntology(OWLOntologyFactoryImpl.java:195)
        uk.ac.manchester.cs.owl.owlapi.OWLOntologyManagerImpl.load(OWLOntologyManagerImpl.java:1105)
        uk.ac.manchester.cs.owl.owlapi.OWLOntologyManagerImpl.loadOntology(OWLOntologyManagerImpl.java:1055)
        uk.ac.manchester.cs.owl.owlapi.OWLOntologyManagerImpl.loadOntologyFromOntologyDocument(OWLOntologyManagerImpl.java:1005)
        com.github.owlcs.ontapi.tmp.TmpTurtleInvestigation.main(TmpTurtleInvestigation.java:25)



	at uk.ac.manchester.cs.owl.owlapi.OWLOntologyFactoryImpl.loadOWLOntology(OWLOntologyFactoryImpl.java:236)
	at uk.ac.manchester.cs.owl.owlapi.OWLOntologyManagerImpl.load(OWLOntologyManagerImpl.java:1105)
	at uk.ac.manchester.cs.owl.owlapi.OWLOntologyManagerImpl.loadOntology(OWLOntologyManagerImpl.java:1055)
	at uk.ac.manchester.cs.owl.owlapi.OWLOntologyManagerImpl.loadOntologyFromOntologyDocument(OWLOntologyManagerImpl.java:1005)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions