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 2015/06/22 22:38:00 UTC
[1/2] jena git commit: JENA-972 : Formatting of blocks of triples.
Repository: jena
Updated Branches:
refs/heads/master f3146bca6 -> 3033e4408
JENA-972 : Formatting of blocks of triples.
Project: http://git-wip-us.apache.org/repos/asf/jena/repo
Commit: http://git-wip-us.apache.org/repos/asf/jena/commit/bcac4e4e
Tree: http://git-wip-us.apache.org/repos/asf/jena/tree/bcac4e4e
Diff: http://git-wip-us.apache.org/repos/asf/jena/diff/bcac4e4e
Branch: refs/heads/master
Commit: bcac4e4e90dc797ae7b35c3c3ed10b4375eda00f
Parents: 3758cec
Author: Andy Seaborne <an...@apache.org>
Authored: Mon Jun 22 21:36:40 2015 +0100
Committer: Andy Seaborne <an...@apache.org>
Committed: Mon Jun 22 21:36:40 2015 +0100
----------------------------------------------------------------------
.../sparql/serializer/FormatterElement.java | 94 +++++++++-----------
1 file changed, 42 insertions(+), 52 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/jena/blob/bcac4e4e/jena-arq/src/main/java/org/apache/jena/sparql/serializer/FormatterElement.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/sparql/serializer/FormatterElement.java b/jena-arq/src/main/java/org/apache/jena/sparql/serializer/FormatterElement.java
index 3f90a47..4abb1fa 100644
--- a/jena-arq/src/main/java/org/apache/jena/sparql/serializer/FormatterElement.java
+++ b/jena-arq/src/main/java/org/apache/jena/sparql/serializer/FormatterElement.java
@@ -54,7 +54,7 @@ public class FormatterElement extends FormatterBase
public static final boolean GROUP_SEP_DOT = false ;
/** Control whether the first item of a group is on the same line as the { */
- public static final boolean GROUP_FIRST_ON_SAME_LINE = false ;
+ public static final boolean GROUP_FIRST_ON_SAME_LINE = true ;
/** Control pretty printing */
public static final boolean PRETTY_PRINT = true ;
@@ -62,9 +62,6 @@ public class FormatterElement extends FormatterBase
/** Control whether disjunction has set of delimiters - as it's a group usually, these aren't needed */
public static final boolean UNION_MARKERS = false ;
- /** Control whether a group of one is unnested - changes the query syntax tree */
- public static final boolean GROUP_UNNEST_ONE = false ;
-
/** Control whether GRAPH indents in a fixed way or based on the layout size */
public static final boolean GRAPH_FIXED_INDENT = true ;
@@ -116,42 +113,40 @@ public class FormatterElement extends FormatterBase
}
formatTriples(el.getPattern()) ;
}
-
+
@Override
- public void visit(ElementPathBlock el)
- {
- if ( el.isEmpty() )
- {
- out.println("# Empty BGP") ;
- return ;
- }
- // Could be neater.
- boolean first = true ;
- PathBlock pBlk = el.getPattern() ;
- for ( TriplePath tp : pBlk )
- {
- if ( ! first )
- {
- out.println(" .") ;
- }
- first = false ;
- if ( tp.isTriple() )
- {
- printSubject(tp.getSubject()) ;
- out.print(" ") ;
- printProperty(tp.getPredicate()) ;
- out.print(" ") ;
- printObject(tp.getObject()) ;
- }
- else
- {
- printSubject(tp.getSubject()) ;
- out.print(" ") ;
- PathWriter.write(out, tp.getPath(), context.getPrologue()) ;
- out.print(" ") ;
- printObject(tp.getObject()) ;
- }
- }
+ public void visit(ElementPathBlock el) {
+ if ( el.isEmpty() )
+ {
+ out.println("# Empty BGP") ;
+ return ;
+ }
+
+ // Split into BGP-path-BGP-...
+ PathBlock pBlk = el.getPattern() ;
+ BasicPattern bgp = new BasicPattern() ;
+ boolean first = true ;
+ for ( TriplePath tp : pBlk )
+ {
+ if ( tp.isTriple() ) {
+ bgp.add(tp.asTriple());
+ continue ;
+ }
+ flush(bgp) ;
+ out.println(" .") ;
+ // Path
+ printSubject(tp.getSubject()) ;
+ out.print(" ") ;
+ PathWriter.write(out, tp.getPath(), context.getPrologue()) ;
+ out.print(" ") ;
+ printObject(tp.getObject()) ;
+ }
+ flush(bgp) ;
+ }
+
+ private void flush(BasicPattern bgp) {
+ formatTriples(bgp) ;
+ bgp.getList().clear();
}
@Override
@@ -292,17 +287,10 @@ public class FormatterElement extends FormatterBase
@Override
public void visit(ElementGroup el)
{
- if ( GROUP_UNNEST_ONE && el.getElements().size() == 1 )
- {
- // If this is an element of just one, we can remove the {} if it is a group.
- Element e = el.getElements().get(0) ;
- visitAsGroup(e) ;
- return ;
- }
-
out.print("{") ;
+ int initialRowNumber = out.getRow() ;
out.incIndent(INDENT) ;
- if ( GROUP_FIRST_ON_SAME_LINE )
+ if ( ! GROUP_FIRST_ON_SAME_LINE )
out.newline() ;
int row1 = out.getRow() ;
@@ -335,6 +323,8 @@ public class FormatterElement extends FormatterBase
out.newline() ;
// Finally, close the group.
+ if ( out.getRow() == initialRowNumber )
+ out.print(" ") ;
out.print("}") ;
}
@@ -525,7 +515,7 @@ public class FormatterElement extends FormatterBase
if ( subj != null )
{
if ( ! first )
- out.println() ;
+ out.println(" .") ;
formatSameSubject(subj, subjAcc) ;
first = false ;
// At end of line of a block of triples with same subject.
@@ -542,7 +532,7 @@ public class FormatterElement extends FormatterBase
if ( subj != null && subjAcc.size() != 0 )
{
if ( ! first )
- out.println() ;
+ out.println(" .") ;
first = false ;
formatSameSubject(subj, subjAcc) ;
}
@@ -577,7 +567,7 @@ public class FormatterElement extends FormatterBase
out.incIndent(indent) ;
}
- // Remained of first triple
+ // Remainder of first triple
printProperty(t1.getPredicate()) ;
printGap() ;
printObject(t1.getObject()) ;
@@ -597,7 +587,7 @@ public class FormatterElement extends FormatterBase
// Finish off the block.
out.decIndent(indent) ;
- out.print(" .") ;
+ //out.print(" .") ;
}
private void setWidths(BasicPattern triples)
[2/2] jena git commit: Merge branch 'master' of
https://git-wip-us.apache.org/repos/asf/jena
Posted by an...@apache.org.
Merge branch 'master' of https://git-wip-us.apache.org/repos/asf/jena
Project: http://git-wip-us.apache.org/repos/asf/jena/repo
Commit: http://git-wip-us.apache.org/repos/asf/jena/commit/3033e440
Tree: http://git-wip-us.apache.org/repos/asf/jena/tree/3033e440
Diff: http://git-wip-us.apache.org/repos/asf/jena/diff/3033e440
Branch: refs/heads/master
Commit: 3033e44080509e7105e75773775fde20c377c2a1
Parents: bcac4e4 f3146bc
Author: Andy Seaborne <an...@apache.org>
Authored: Mon Jun 22 21:37:38 2015 +0100
Committer: Andy Seaborne <an...@apache.org>
Committed: Mon Jun 22 21:37:38 2015 +0100
----------------------------------------------------------------------
jena-parent/pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------