You are viewing a plain text version of this content. The canonical link for it is here.
Posted to pr@jena.apache.org by GitBox <gi...@apache.org> on 2020/12/14 10:56:59 UTC

[GitHub] [jena] afs opened a new pull request #886: JENA-2015: RDF* annotation syntax

afs opened a new pull request #886:
URL: https://github.com/apache/jena/pull/886


   [JENA-2015](https://issues.apache.org/jira/projects/JENA/issues/JENA-2015)
   
   includes as noted the Javacc turtle parser cleanup.
   
   Does not include companion SPARQL* annotation syntax. (RDF* term syntax is already implemented.)


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@jena.apache.org
For additional commands, e-mail: pr-help@jena.apache.org


[GitHub] [jena] afs commented on a change in pull request #886: JENA-2015: RDF* annotation syntax

Posted by GitBox <gi...@apache.org>.
afs commented on a change in pull request #886:
URL: https://github.com/apache/jena/pull/886#discussion_r543622457



##########
File path: jena-arq/src/main/java/org/apache/jena/riot/lang/extra/LangParserBase.java
##########
@@ -0,0 +1,201 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jena.riot.lang.extra;
+
+import org.apache.jena.atlas.AtlasException;
+import org.apache.jena.atlas.lib.EscapeStr;
+import org.apache.jena.datatypes.RDFDatatype;
+import org.apache.jena.datatypes.TypeMapper;
+import org.apache.jena.datatypes.xsd.XSDDatatype;
+import org.apache.jena.graph.Node;
+import org.apache.jena.graph.NodeFactory;
+import org.apache.jena.graph.Triple;
+import org.apache.jena.query.ARQ;
+import org.apache.jena.query.QueryParseException;
+import org.apache.jena.riot.RiotException;
+import org.apache.jena.riot.RiotParseException;
+import org.apache.jena.riot.system.ParserProfile;
+import org.apache.jena.riot.system.RiotLib;
+import org.apache.jena.riot.system.StreamRDF;
+import org.apache.jena.sparql.graph.NodeConst;
+import org.apache.jena.sparql.lang.ParserBase;
+import org.apache.jena.vocabulary.RDF;
+
+/** 
+ * Base for JavaCC parser of RDF languages.
+ * See {@link ParserBase} for the base class for SPARQL. 
+ */
+public class LangParserBase {
+
+    protected final Node XSD_TRUE       = NodeConst.nodeTrue ;
+    protected final Node XSD_FALSE      = NodeConst.nodeFalse ;
+
+    protected final Node nRDFtype       = NodeConst.nodeRDFType ;
+
+    protected final Node nRDFnil        = NodeConst.nodeNil ;
+    protected final Node nRDFfirst      = NodeConst.nodeFirst ;
+    protected final Node nRDFrest       = NodeConst.nodeRest ;
+
+    protected final Node nRDFsubject    = RDF.Nodes.subject ;
+    protected final Node nRDFpredicate  = RDF.Nodes.predicate ;
+    protected final Node nRDFobject     = RDF.Nodes.object ;
+
+    protected StreamRDF stream;
+    protected ParserProfile profile;
+
+    public LangParserBase() { }
+    
+    // These are essential calls unless the parser takes over the functions. 
+    // They can't easily be in the constructor because this class is inherited
+    // by the JaavCC generated parser.
+    public void setProfile(ParserProfile profile) {
+        this.profile = profile;
+    }
+
+    public void setDest(StreamRDF stream) {
+        this.stream = stream;
+    }
+    
+    // ----
+    
+    protected String fixupPrefix(String prefix, int line, int column) {
+        if ( prefix.endsWith(":") )
+            prefix = prefix.substring(0, prefix.length() - 1) ;
+        return prefix ;
+    }
+
+    protected Node createNode(String iriStr) {
+        return profile.createURI(iriStr, -1, -1);
+    }
+
+    protected Node createBNode(int line, int column) {
+        return profile.createBlankNode(null, line, column);
+    }
+
+    protected Node createBNode(String label, int line, int column) {
+        return profile.createBlankNode(null, label, line, column);
+    }
+
+    protected Node createListNode(int line, int column) {
+        return  createBNode(line, column);
+    }
+
+    protected void checkString(String string, int line, int column) {
+        for ( int i = 0 ; i < string.length() ; i++ ) {
+            // Not "codePointAt" which does surrogate processing.
+            char ch = string.charAt(i);
+            // Check surrogate pairs are pairs.
+            if ( Character.isHighSurrogate(ch) ) {
+                i++;
+                if ( i == string.length() )
+                    throw new QueryParseException("Bad surrogate pair (end of string)", line, column);
+                char ch1 = string.charAt(i);
+                if ( ! Character.isLowSurrogate(ch1) ) {
+                    throw new QueryParseException("Bad surrogate pair (high surrogate not followed by low surrogate)", line, column);
+                }
+            } else if ( Character.isLowSurrogate(ch) ) {
+                throw new QueryParseException("Bad surrogate pair (low surrogate without high surrogate)", line, column);
+            }
+        }
+    }

Review comment:
       Duplicated; there is some other methods copied as well.
   
   The tiny difference is that the exceptions are RiotParseException ... except I missed this method!  Changed.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@jena.apache.org
For additional commands, e-mail: pr-help@jena.apache.org


[GitHub] [jena] kinow commented on a change in pull request #886: JENA-2015: RDF* annotation syntax

Posted by GitBox <gi...@apache.org>.
kinow commented on a change in pull request #886:
URL: https://github.com/apache/jena/pull/886#discussion_r542947330



##########
File path: jena-arq/src/main/java/org/apache/jena/riot/lang/extra/LangParserBase.java
##########
@@ -0,0 +1,201 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jena.riot.lang.extra;
+
+import org.apache.jena.atlas.AtlasException;
+import org.apache.jena.atlas.lib.EscapeStr;
+import org.apache.jena.datatypes.RDFDatatype;
+import org.apache.jena.datatypes.TypeMapper;
+import org.apache.jena.datatypes.xsd.XSDDatatype;
+import org.apache.jena.graph.Node;
+import org.apache.jena.graph.NodeFactory;
+import org.apache.jena.graph.Triple;
+import org.apache.jena.query.ARQ;
+import org.apache.jena.query.QueryParseException;
+import org.apache.jena.riot.RiotException;
+import org.apache.jena.riot.RiotParseException;
+import org.apache.jena.riot.system.ParserProfile;
+import org.apache.jena.riot.system.RiotLib;
+import org.apache.jena.riot.system.StreamRDF;
+import org.apache.jena.sparql.graph.NodeConst;
+import org.apache.jena.sparql.lang.ParserBase;
+import org.apache.jena.vocabulary.RDF;
+
+/** 
+ * Base for JavaCC parser of RDF languages.
+ * See {@link ParserBase} for the base class for SPARQL. 
+ */
+public class LangParserBase {
+
+    protected final Node XSD_TRUE       = NodeConst.nodeTrue ;
+    protected final Node XSD_FALSE      = NodeConst.nodeFalse ;
+
+    protected final Node nRDFtype       = NodeConst.nodeRDFType ;
+
+    protected final Node nRDFnil        = NodeConst.nodeNil ;
+    protected final Node nRDFfirst      = NodeConst.nodeFirst ;
+    protected final Node nRDFrest       = NodeConst.nodeRest ;
+
+    protected final Node nRDFsubject    = RDF.Nodes.subject ;
+    protected final Node nRDFpredicate  = RDF.Nodes.predicate ;
+    protected final Node nRDFobject     = RDF.Nodes.object ;
+
+    protected StreamRDF stream;
+    protected ParserProfile profile;
+
+    public LangParserBase() { }
+    
+    // These are essential calls unless the parser takes over the functions. 
+    // They can't easily be in the constructor because this class is inherited
+    // by the JaavCC generated parser.

Review comment:
       s/JaavCC/JavaCC

##########
File path: jena-arq/src/main/java/org/apache/jena/riot/RDFParser.java
##########
@@ -334,8 +334,11 @@ private void parseNotUri(StreamRDF destination) {
             throw new RiotException("Failed to determine the RDF syntax (.lang or .base required)");
 
         ReaderRIOT readerRiot = createReader(ct);
-        if ( readerRiot == null )
-            throw new RiotException("No parser registered for content type: " + ct.getContentTypeStr());
+        if ( readerRiot == null ) {
+//            readerRiot = createReader(lang);
+//            if ( readerRiot == null )
+                throw new RiotException("No parser registered for content type: " + ct.getContentTypeStr());

Review comment:
       Format/delete?

##########
File path: jena-arq/src/main/java/org/apache/jena/riot/lang/extra/LangParserBase.java
##########
@@ -0,0 +1,201 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jena.riot.lang.extra;
+
+import org.apache.jena.atlas.AtlasException;
+import org.apache.jena.atlas.lib.EscapeStr;
+import org.apache.jena.datatypes.RDFDatatype;
+import org.apache.jena.datatypes.TypeMapper;
+import org.apache.jena.datatypes.xsd.XSDDatatype;
+import org.apache.jena.graph.Node;
+import org.apache.jena.graph.NodeFactory;
+import org.apache.jena.graph.Triple;
+import org.apache.jena.query.ARQ;
+import org.apache.jena.query.QueryParseException;
+import org.apache.jena.riot.RiotException;
+import org.apache.jena.riot.RiotParseException;
+import org.apache.jena.riot.system.ParserProfile;
+import org.apache.jena.riot.system.RiotLib;
+import org.apache.jena.riot.system.StreamRDF;
+import org.apache.jena.sparql.graph.NodeConst;
+import org.apache.jena.sparql.lang.ParserBase;
+import org.apache.jena.vocabulary.RDF;
+
+/** 
+ * Base for JavaCC parser of RDF languages.
+ * See {@link ParserBase} for the base class for SPARQL. 
+ */
+public class LangParserBase {
+
+    protected final Node XSD_TRUE       = NodeConst.nodeTrue ;
+    protected final Node XSD_FALSE      = NodeConst.nodeFalse ;
+
+    protected final Node nRDFtype       = NodeConst.nodeRDFType ;
+
+    protected final Node nRDFnil        = NodeConst.nodeNil ;
+    protected final Node nRDFfirst      = NodeConst.nodeFirst ;
+    protected final Node nRDFrest       = NodeConst.nodeRest ;
+
+    protected final Node nRDFsubject    = RDF.Nodes.subject ;
+    protected final Node nRDFpredicate  = RDF.Nodes.predicate ;
+    protected final Node nRDFobject     = RDF.Nodes.object ;
+
+    protected StreamRDF stream;
+    protected ParserProfile profile;
+
+    public LangParserBase() { }
+    
+    // These are essential calls unless the parser takes over the functions. 
+    // They can't easily be in the constructor because this class is inherited
+    // by the JaavCC generated parser.
+    public void setProfile(ParserProfile profile) {
+        this.profile = profile;
+    }
+
+    public void setDest(StreamRDF stream) {
+        this.stream = stream;
+    }
+    
+    // ----
+    
+    protected String fixupPrefix(String prefix, int line, int column) {
+        if ( prefix.endsWith(":") )
+            prefix = prefix.substring(0, prefix.length() - 1) ;
+        return prefix ;
+    }
+
+    protected Node createNode(String iriStr) {
+        return profile.createURI(iriStr, -1, -1);
+    }
+
+    protected Node createBNode(int line, int column) {
+        return profile.createBlankNode(null, line, column);
+    }
+
+    protected Node createBNode(String label, int line, int column) {
+        return profile.createBlankNode(null, label, line, column);
+    }
+
+    protected Node createListNode(int line, int column) {
+        return  createBNode(line, column);
+    }
+
+    protected void checkString(String string, int line, int column) {
+        for ( int i = 0 ; i < string.length() ; i++ ) {
+            // Not "codePointAt" which does surrogate processing.
+            char ch = string.charAt(i);
+            // Check surrogate pairs are pairs.
+            if ( Character.isHighSurrogate(ch) ) {
+                i++;
+                if ( i == string.length() )
+                    throw new QueryParseException("Bad surrogate pair (end of string)", line, column);
+                char ch1 = string.charAt(i);
+                if ( ! Character.isLowSurrogate(ch1) ) {
+                    throw new QueryParseException("Bad surrogate pair (high surrogate not followed by low surrogate)", line, column);
+                }
+            } else if ( Character.isLowSurrogate(ch) ) {
+                throw new QueryParseException("Bad surrogate pair (low surrogate without high surrogate)", line, column);
+            }
+        }
+    }

Review comment:
       Was this code elsewhere and it was then moved here? Or is it duplicated? I remember seeing some similar code a few days ago I think.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@jena.apache.org
For additional commands, e-mail: pr-help@jena.apache.org


[GitHub] [jena] afs merged pull request #886: JENA-2015: RDF* annotation syntax

Posted by GitBox <gi...@apache.org>.
afs merged pull request #886:
URL: https://github.com/apache/jena/pull/886


   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@jena.apache.org
For additional commands, e-mail: pr-help@jena.apache.org


[GitHub] [jena] afs commented on pull request #886: JENA-2015: RDF* annotation syntax

Posted by GitBox <gi...@apache.org>.
afs commented on pull request #886:
URL: https://github.com/apache/jena/pull/886#issuecomment-745517437


   There are some functions copied - the exceptions are different (QueryParseException vs RiotParseException) - except I missed this function so updated to RiotParseException.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@jena.apache.org
For additional commands, e-mail: pr-help@jena.apache.org