You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jena.apache.org by an...@apache.org on 2013/07/03 21:55:58 UTC

svn commit: r1499539 - /jena/trunk/jena-arq/src/main/java/org/apache/jena/riot/lang/LangTriG.java

Author: andy
Date: Wed Jul  3 19:55:57 2013
New Revision: 1499539

URL: http://svn.apache.org/r1499539
Log:
Correct comments and reformat.

Modified:
    jena/trunk/jena-arq/src/main/java/org/apache/jena/riot/lang/LangTriG.java

Modified: jena/trunk/jena-arq/src/main/java/org/apache/jena/riot/lang/LangTriG.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-arq/src/main/java/org/apache/jena/riot/lang/LangTriG.java?rev=1499539&r1=1499538&r2=1499539&view=diff
==============================================================================
--- jena/trunk/jena-arq/src/main/java/org/apache/jena/riot/lang/LangTriG.java (original)
+++ jena/trunk/jena-arq/src/main/java/org/apache/jena/riot/lang/LangTriG.java Wed Jul  3 19:55:57 2013
@@ -16,7 +16,7 @@
  * limitations under the License.
  */
 
-package org.apache.jena.riot.lang;
+package org.apache.jena.riot.lang ;
 
 import static org.apache.jena.riot.tokens.TokenType.DOT ;
 import static org.apache.jena.riot.tokens.TokenType.RBRACE ;
@@ -31,68 +31,49 @@ import org.apache.jena.riot.tokens.Token
 import com.hp.hpl.jena.graph.Node ;
 import com.hp.hpl.jena.sparql.core.Quad ;
 
-/** TriG language: http://www4.wiwiss.fu-berlin.de/bizer/TriG/
- *  Generalizations:
- *    Can have multiple default graph blocks.
- *    
- * 
- */
-public class LangTriG extends LangTurtleBase<Quad>
-{
-    /*
-        TriGDoc     ::=      ws* (statement ws*)*
-        statement   ::=     directive ws* '.' | graph
-        graph       ::=     graphName? ws* '='? ws* '{' ws* (triples ws* ('.' ws* triples ws*)* '.'? ws*)? '}' ws* '.'?
-        graphName   ::=     resource
-        
-        We may add:
-        statement   ::=     directive ws* '.' | graph | quad
-        quad        ::=     subject predicate object resource?
-          (i.e. raw inline nquads except with prefix names)
-     */
-    
-    public LangTriG(Tokenizer tokens, ParserProfile profile, StreamRDF dest) 
-    {
+/** TriG language: http://www.w3.org/TR/trig/ */
+public class LangTriG extends LangTurtleBase<Quad> {
+
+    public LangTriG(Tokenizer tokens, ParserProfile profile, StreamRDF dest) {
         super(tokens, profile, dest) ;
     }
-    
+
     @Override
-    public Lang getLang()   { return RDFLanguages.TRIG ; }
+    public Lang getLang() {
+        return RDFLanguages.TRIG ;
+    }
 
     @Override
-    protected final void oneTopLevelElement()
-    {
+    protected final void oneTopLevelElement() {
         oneNamedGraphBlock() ;
     }
-    
-    protected final void oneNamedGraphBlock()
-    {
+
+    protected final void oneNamedGraphBlock() {
         // Directives are only between graph blocks.
         Node graphNode = null ;
         Token token = peekToken() ;
-        Token t = token ;   // Keep for error message.
-        
-        // Sort out the graph node if any.
-        // This code pasres bNodes as graph labels correctly, then checks whether 
-        
-        if (token.getType() == TokenType.LBRACKET) {
+        Token t = token ; // Keep for error message.
+
+        // [ ] { ... }
+        if ( token.getType() == TokenType.LBRACKET ) {
             nextToken() ;
             token = peekToken() ;
-            if (token.getType() != TokenType.RBRACKET) 
+            if ( token.getType() != TokenType.RBRACKET )
                 exception(t, "Broken term: [ not followed by ]") ;
 
             graphNode = profile.createBlankNode(graphNode, t.getLine(), t.getColumn()) ;
             nextToken() ;
         } else {
-            if (token.isNode()) {
+            // <uri> { ... }
+            // { ... }
+            if ( token.isNode() ) {
                 graphNode = node() ;
                 nextToken() ;
             }
         }
-        
-        if (graphNode != null)
-        {
-            if (graphNode.isURI() || graphNode.isBlank())
+
+        if ( graphNode != null ) {
+            if ( graphNode.isURI() || graphNode.isBlank() )
                 setCurrentGraph(graphNode) ;
             else
                 exception(t, "Not a legal graph name: " + graphNode) ;
@@ -100,10 +81,11 @@ public class LangTriG extends LangTurtle
             setCurrentGraph(Quad.tripleInQuad) ;
 
         token = peekToken() ;
-        
+
         // = is optional and old style.
-        if (token.getType() == TokenType.EQUALS) {
-            if (profile.isStrictMode()) exception(token, "Use of = {} is not part of standard TriG: " + graphNode) ;
+        if ( token.getType() == TokenType.EQUALS ) {
+            if ( profile.isStrictMode() )
+                exception(token, "Use of = {} is not part of standard TriG: " + graphNode) ;
             // Skip.
             nextToken() ;
             token = peekToken() ;
@@ -112,70 +94,64 @@ public class LangTriG extends LangTurtle
         if ( token.getType() != TokenType.LBRACE )
             exception(token, "Expected start of graph: got %s", peekToken()) ;
         nextToken() ;
-        
+
         // **** Turtle but no directives.
-        
-        while(true)
-        {
+
+        while (true) {
             token = peekToken() ;
             if ( token.hasType(TokenType.RBRACE) )
                 break ;
-            // No - this has Turtle termination rules.
-            // Assume this is fixed then ....
-            
-            // Unlike many operations in this parser suite 
-            // this does not assume that we are definitel entering
-            // this sttae throws an error if the first token 
+            // Unlike many operations in this parser suite
+            // this does not assume that we are definitely entering
+            // this state throws an error if the first token
             triplesSameSubject() ;
         }
-        
+
         // **** Turtle.
         token = nextToken() ;
         if ( token.getType() != TokenType.RBRACE )
             exception(token, "Expected end of graph: got %s", token) ;
-        
+
         // Skip DOT
         token = peekToken() ;
         if ( token.hasType(TokenType.DOT) )
             nextToken() ;
-        
+
         // End graph block.
         setCurrentGraph(Quad.tripleInQuad) ;
     }
 
     @Override
-    protected void expectEndOfTriples()
-    {
+    protected void expectEndOfTriples() {
         // The DOT is required by Turtle (strictly).
         // It is not in N3 and SPARQL or TriG
-        
-//        // To make trailing DOT illegal in strict TriG.
-//        if ( profile.isStrictMode() ) {
-//            expect("Triples not terminated by DOT", DOT) ;
-//            return ;
-//        }
-        
+
+        // // To make trailing DOT illegal in strict TriG.
+        // if ( profile.isStrictMode() ) {
+        // expect("Triples not terminated by DOT", DOT) ;
+        // return ;
+        // }
+
         if ( lookingAt(DOT) ) {
             nextToken() ;
             return ;
         }
-        
+
         // Loose - DOT optional.
         if ( lookingAt(RBRACE) )
-            // Don't consume the RBRACE - used to break the loop of triples blocks.
+            // Don't consume the RBRACE - used to break the loop of triples
+            // blocks.
             return ;
         exception(peekToken(), "Triples not terminated properly: expected '.', '}' or EOF: got %s", peekToken()) ;
     }
 
-    
     @Override
-    protected void emit(Node subject, Node predicate, Node object)
-    {
+    protected void emit(Node subject, Node predicate, Node object) {
         Node graph = getCurrentGraph() ;
-        
+
         if ( graph == Quad.defaultGraphNodeGenerated )
             graph = Quad.tripleInQuad ;
-        
+
         Quad quad = profile.createQuad(graph, subject, predicate, object, currLine, currCol) ;
         dest.quad(quad) ;
     }