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 2016/05/14 17:22:17 UTC
[21/40] jena git commit: Fix line endings
http://git-wip-us.apache.org/repos/asf/jena/blob/d6ae87fd/jena-csv/src/main/java/org/apache/jena/propertytable/graph/GraphPropertyTable.java
----------------------------------------------------------------------
diff --git a/jena-csv/src/main/java/org/apache/jena/propertytable/graph/GraphPropertyTable.java b/jena-csv/src/main/java/org/apache/jena/propertytable/graph/GraphPropertyTable.java
index 7e5e5b5..b538173 100644
--- a/jena-csv/src/main/java/org/apache/jena/propertytable/graph/GraphPropertyTable.java
+++ b/jena-csv/src/main/java/org/apache/jena/propertytable/graph/GraphPropertyTable.java
@@ -1,200 +1,200 @@
-/*
- * 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.propertytable.graph;
-
-import java.util.ArrayList ;
-import java.util.Locale ;
-import java.util.function.Predicate;
-
-import org.apache.jena.graph.Node ;
-import org.apache.jena.graph.NodeFactory ;
-import org.apache.jena.graph.Triple ;
-import org.apache.jena.graph.impl.GraphBase ;
-import org.apache.jena.propertytable.Column ;
-import org.apache.jena.propertytable.PropertyTable ;
-import org.apache.jena.propertytable.Row ;
-import org.apache.jena.sparql.core.BasicPattern ;
-import org.apache.jena.util.iterator.ExtendedIterator ;
-import org.apache.jena.util.iterator.NullIterator ;
-import org.apache.jena.util.iterator.WrappedIterator ;
-
-/**
- * GraphPropertyTable implements the Graph interface (read-only) over a PropertyTable.
- * This is subclass from GraphBase and implements find().
- * The graphBaseFind()(for matching a Triple) and propertyTableBaseFind()(for matching a whole Row) methods can choose the access route based on the find arguments.
- * GraphPropertyTable holds/wraps an reference of the PropertyTable instance, so that such a Graph can be treated in a more table-like fashion.
- *
- */
-public class GraphPropertyTable extends GraphBase {
-
- private PropertyTable pt;
-
- public GraphPropertyTable(PropertyTable pt) {
- this.pt = pt;
- }
-
- public PropertyTable getPropertyTable() {
- return pt;
- }
-
- @Override
- protected ExtendedIterator<Triple> graphBaseFind(Triple triple) {
- //System.out.println(m);
-
- if (this.pt == null) {
- return NullIterator.instance();
- }
-
- ExtendedIterator<Triple> iter = null;
-
- Node s = triple.getMatchSubject();
- Node p = triple.getMatchPredicate();
- Node o = triple.getMatchObject();
-
- if (isConcrete(p) && isConcrete(o)) {
- //System.out.println("1");
- iter = pt.getTripleIterator(pt.getColumn(p), o);
- } else if (isConcrete(p)) {
- //System.out.println("2");
- Column column = this.pt.getColumn(p);
- if (column != null) {
- iter = pt.getTripleIterator(column);
- } else {
- return NullIterator.instance();
- }
- } else if (isConcrete(o)) {
- //System.out.println("3");
- iter = pt.getTripleIterator(o);
- } else{
- //System.out.println("4");
- iter = pt.getTripleIterator();
- }
-
- return iter.filterKeep(new TripleMatchFilterEquality(triple));
-
- }
-
- protected ExtendedIterator<Row> propertyTableBaseFind(RowMatch m) {
-
- if (this.pt == null) {
- return NullIterator.instance();
- }
-
- ExtendedIterator<Row> iter = null;
-
- Node s = m.getMatchSubject();
-
- if ( isConcrete(s) ){
- Row row= pt.getRow(s);
- if (row == null){
- return NullIterator.instance();
- } else {
- ArrayList<Row> rows = new ArrayList<Row>();
- rows.add(row);
- return WrappedIterator.create(rows.iterator());
- }
- } else {
- iter = WrappedIterator.create(pt.getAllRows().iterator());
- }
-
- return iter.filterKeep(new RowMatchFilterEquality( m ));
-
- }
-
- static class RowMatchFilterEquality implements Predicate<Row> {
- final protected RowMatch rMatch;
-
- public RowMatchFilterEquality(RowMatch rMatch) {
- this.rMatch = rMatch;
- }
-
- @Override
- public boolean test(Row r) {
- return rowContained(rMatch, r);
- }
-
- }
-
- static boolean rowContained(RowMatch rMatch, Row row) {
-
- boolean contained = equalNode(rMatch.getSubject(), row.getRowKey());
- if(contained){
- BasicPattern pattern =rMatch.getBasicPattern();
- for(Triple triple: pattern ){
- contained = equalNode(triple.getObject(), row.getValue( triple.getPredicate()) );
- if (! contained){
- break;
- }
- }
- }
- return contained;
- }
-
-
- static class TripleMatchFilterEquality implements Predicate<Triple> {
- final protected Triple tMatch;
-
- /** Creates new TripleMatchFilter */
- public TripleMatchFilterEquality(Triple tMatch) {
- this.tMatch = tMatch;
- }
-
- @Override
- public boolean test(Triple t) {
- return tripleContained(tMatch, t);
- }
-
- }
-
- static boolean tripleContained(Triple patternTriple, Triple dataTriple) {
- return equalNode(patternTriple.getSubject(), dataTriple.getSubject())
- && equalNode(patternTriple.getPredicate(),
- dataTriple.getPredicate())
- && equalNode(patternTriple.getObject(), dataTriple.getObject());
- }
-
- private static boolean equalNode(Node m, Node n) {
- // m should not be null unless .getMatchXXXX used to get the node.
- // Language tag canonicalization
- n = fixupNode(n);
- m = fixupNode(m);
- return (m == null) || (m == Node.ANY) || m.equals(n);
- }
-
- private static Node fixupNode(Node node) {
- if (node == null || node == Node.ANY)
- return node;
-
- // RDF says ... language tags should be canonicalized to lower case.
- if (node.isLiteral()) {
- String lang = node.getLiteralLanguage();
- if (lang != null && !lang.equals(""))
- node = NodeFactory.createLiteral(node.getLiteralLexicalForm(),
- lang.toLowerCase(Locale.ROOT),
- node.getLiteralDatatype());
- }
- return node;
- }
-
- private boolean isConcrete(Node node) {
- boolean wild = (node == null || node == Node.ANY);
- return !wild;
- }
-
-}
+/*
+ * 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.propertytable.graph;
+
+import java.util.ArrayList ;
+import java.util.Locale ;
+import java.util.function.Predicate;
+
+import org.apache.jena.graph.Node ;
+import org.apache.jena.graph.NodeFactory ;
+import org.apache.jena.graph.Triple ;
+import org.apache.jena.graph.impl.GraphBase ;
+import org.apache.jena.propertytable.Column ;
+import org.apache.jena.propertytable.PropertyTable ;
+import org.apache.jena.propertytable.Row ;
+import org.apache.jena.sparql.core.BasicPattern ;
+import org.apache.jena.util.iterator.ExtendedIterator ;
+import org.apache.jena.util.iterator.NullIterator ;
+import org.apache.jena.util.iterator.WrappedIterator ;
+
+/**
+ * GraphPropertyTable implements the Graph interface (read-only) over a PropertyTable.
+ * This is subclass from GraphBase and implements find().
+ * The graphBaseFind()(for matching a Triple) and propertyTableBaseFind()(for matching a whole Row) methods can choose the access route based on the find arguments.
+ * GraphPropertyTable holds/wraps an reference of the PropertyTable instance, so that such a Graph can be treated in a more table-like fashion.
+ *
+ */
+public class GraphPropertyTable extends GraphBase {
+
+ private PropertyTable pt;
+
+ public GraphPropertyTable(PropertyTable pt) {
+ this.pt = pt;
+ }
+
+ public PropertyTable getPropertyTable() {
+ return pt;
+ }
+
+ @Override
+ protected ExtendedIterator<Triple> graphBaseFind(Triple triple) {
+ //System.out.println(m);
+
+ if (this.pt == null) {
+ return NullIterator.instance();
+ }
+
+ ExtendedIterator<Triple> iter = null;
+
+ Node s = triple.getMatchSubject();
+ Node p = triple.getMatchPredicate();
+ Node o = triple.getMatchObject();
+
+ if (isConcrete(p) && isConcrete(o)) {
+ //System.out.println("1");
+ iter = pt.getTripleIterator(pt.getColumn(p), o);
+ } else if (isConcrete(p)) {
+ //System.out.println("2");
+ Column column = this.pt.getColumn(p);
+ if (column != null) {
+ iter = pt.getTripleIterator(column);
+ } else {
+ return NullIterator.instance();
+ }
+ } else if (isConcrete(o)) {
+ //System.out.println("3");
+ iter = pt.getTripleIterator(o);
+ } else{
+ //System.out.println("4");
+ iter = pt.getTripleIterator();
+ }
+
+ return iter.filterKeep(new TripleMatchFilterEquality(triple));
+
+ }
+
+ protected ExtendedIterator<Row> propertyTableBaseFind(RowMatch m) {
+
+ if (this.pt == null) {
+ return NullIterator.instance();
+ }
+
+ ExtendedIterator<Row> iter = null;
+
+ Node s = m.getMatchSubject();
+
+ if ( isConcrete(s) ){
+ Row row= pt.getRow(s);
+ if (row == null){
+ return NullIterator.instance();
+ } else {
+ ArrayList<Row> rows = new ArrayList<Row>();
+ rows.add(row);
+ return WrappedIterator.create(rows.iterator());
+ }
+ } else {
+ iter = WrappedIterator.create(pt.getAllRows().iterator());
+ }
+
+ return iter.filterKeep(new RowMatchFilterEquality( m ));
+
+ }
+
+ static class RowMatchFilterEquality implements Predicate<Row> {
+ final protected RowMatch rMatch;
+
+ public RowMatchFilterEquality(RowMatch rMatch) {
+ this.rMatch = rMatch;
+ }
+
+ @Override
+ public boolean test(Row r) {
+ return rowContained(rMatch, r);
+ }
+
+ }
+
+ static boolean rowContained(RowMatch rMatch, Row row) {
+
+ boolean contained = equalNode(rMatch.getSubject(), row.getRowKey());
+ if(contained){
+ BasicPattern pattern =rMatch.getBasicPattern();
+ for(Triple triple: pattern ){
+ contained = equalNode(triple.getObject(), row.getValue( triple.getPredicate()) );
+ if (! contained){
+ break;
+ }
+ }
+ }
+ return contained;
+ }
+
+
+ static class TripleMatchFilterEquality implements Predicate<Triple> {
+ final protected Triple tMatch;
+
+ /** Creates new TripleMatchFilter */
+ public TripleMatchFilterEquality(Triple tMatch) {
+ this.tMatch = tMatch;
+ }
+
+ @Override
+ public boolean test(Triple t) {
+ return tripleContained(tMatch, t);
+ }
+
+ }
+
+ static boolean tripleContained(Triple patternTriple, Triple dataTriple) {
+ return equalNode(patternTriple.getSubject(), dataTriple.getSubject())
+ && equalNode(patternTriple.getPredicate(),
+ dataTriple.getPredicate())
+ && equalNode(patternTriple.getObject(), dataTriple.getObject());
+ }
+
+ private static boolean equalNode(Node m, Node n) {
+ // m should not be null unless .getMatchXXXX used to get the node.
+ // Language tag canonicalization
+ n = fixupNode(n);
+ m = fixupNode(m);
+ return (m == null) || (m == Node.ANY) || m.equals(n);
+ }
+
+ private static Node fixupNode(Node node) {
+ if (node == null || node == Node.ANY)
+ return node;
+
+ // RDF says ... language tags should be canonicalized to lower case.
+ if (node.isLiteral()) {
+ String lang = node.getLiteralLanguage();
+ if (lang != null && !lang.equals(""))
+ node = NodeFactory.createLiteral(node.getLiteralLexicalForm(),
+ lang.toLowerCase(Locale.ROOT),
+ node.getLiteralDatatype());
+ }
+ return node;
+ }
+
+ private boolean isConcrete(Node node) {
+ boolean wild = (node == null || node == Node.ANY);
+ return !wild;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/jena/blob/d6ae87fd/jena-csv/src/main/java/org/apache/jena/propertytable/graph/QueryIterPropertyTable.java
----------------------------------------------------------------------
diff --git a/jena-csv/src/main/java/org/apache/jena/propertytable/graph/QueryIterPropertyTable.java b/jena-csv/src/main/java/org/apache/jena/propertytable/graph/QueryIterPropertyTable.java
index 8ebfa72..4349623 100644
--- a/jena-csv/src/main/java/org/apache/jena/propertytable/graph/QueryIterPropertyTable.java
+++ b/jena-csv/src/main/java/org/apache/jena/propertytable/graph/QueryIterPropertyTable.java
@@ -1,114 +1,114 @@
-/*
- * 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.propertytable.graph;
-
-import java.util.ArrayList ;
-import java.util.Collection ;
-import java.util.HashMap ;
-import java.util.List ;
-
-import org.apache.jena.atlas.io.IndentedWriter ;
-import org.apache.jena.atlas.lib.Lib ;
-import org.apache.jena.graph.Graph ;
-import org.apache.jena.graph.Node ;
-import org.apache.jena.graph.Triple ;
-import org.apache.jena.sparql.core.BasicPattern ;
-import org.apache.jena.sparql.engine.ExecutionContext ;
-import org.apache.jena.sparql.engine.QueryIterator ;
-import org.apache.jena.sparql.engine.binding.Binding ;
-import org.apache.jena.sparql.engine.iterator.QueryIter1 ;
-import org.apache.jena.sparql.serializer.SerializationContext ;
-import org.apache.jena.sparql.util.FmtUtils ;
-
-/**
- * Split the incoming BasicPattern by subjects, (i.e. it becomes multiple sub BasicPatterns grouped by the same subjects.
- *
- */
-public class QueryIterPropertyTable extends QueryIter1 {
-
- private BasicPattern pattern;
- private Graph graph;
- private QueryIterator output;
-
- public static QueryIterator create(QueryIterator input,
- BasicPattern pattern, ExecutionContext execContext) {
- return new QueryIterPropertyTable(input, pattern, execContext);
- }
-
- private QueryIterPropertyTable(QueryIterator input, BasicPattern pattern,
- ExecutionContext execContext) {
- super(input, execContext);
- this.pattern = pattern;
- graph = execContext.getActiveGraph();
- // Create a chain of triple iterators.
- QueryIterator chain = getInput();
- Collection<BasicPattern> patterns = sort(pattern);
- for (BasicPattern p : patterns)
- chain = new QueryIterPropertyTableRow(chain, p, execContext);
- output = chain;
- }
-
- private Collection<BasicPattern> sort(BasicPattern pattern) {
- HashMap<Node, BasicPattern> map = new HashMap<Node, BasicPattern>();
- for (Triple triple : pattern.getList()) {
- Node subject = triple.getSubject();
- if (!map.containsKey(subject)) {
- List<Triple> triples = new ArrayList<Triple>();
- BasicPattern p = BasicPattern.wrap(triples);
- map.put(subject, p);
- p.add(triple);
- } else {
- map.get(subject).add(triple);
- }
- }
- return map.values();
- }
-
- @Override
- protected boolean hasNextBinding() {
- return output.hasNext();
- }
-
- @Override
- protected Binding moveToNextBinding() {
- return output.nextBinding();
- }
-
- @Override
- protected void closeSubIterator() {
- if (output != null)
- output.close();
- output = null;
- }
-
- @Override
- protected void requestSubCancel() {
- if (output != null)
- output.cancel();
- }
-
- @Override
- protected void details(IndentedWriter out, SerializationContext sCxt) {
- out.print(Lib.className(this));
- out.println();
- out.incIndent();
- FmtUtils.formatPattern(out, pattern, sCxt);
- out.decIndent();
- }
-}
+/*
+ * 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.propertytable.graph;
+
+import java.util.ArrayList ;
+import java.util.Collection ;
+import java.util.HashMap ;
+import java.util.List ;
+
+import org.apache.jena.atlas.io.IndentedWriter ;
+import org.apache.jena.atlas.lib.Lib ;
+import org.apache.jena.graph.Graph ;
+import org.apache.jena.graph.Node ;
+import org.apache.jena.graph.Triple ;
+import org.apache.jena.sparql.core.BasicPattern ;
+import org.apache.jena.sparql.engine.ExecutionContext ;
+import org.apache.jena.sparql.engine.QueryIterator ;
+import org.apache.jena.sparql.engine.binding.Binding ;
+import org.apache.jena.sparql.engine.iterator.QueryIter1 ;
+import org.apache.jena.sparql.serializer.SerializationContext ;
+import org.apache.jena.sparql.util.FmtUtils ;
+
+/**
+ * Split the incoming BasicPattern by subjects, (i.e. it becomes multiple sub BasicPatterns grouped by the same subjects.
+ *
+ */
+public class QueryIterPropertyTable extends QueryIter1 {
+
+ private BasicPattern pattern;
+ private Graph graph;
+ private QueryIterator output;
+
+ public static QueryIterator create(QueryIterator input,
+ BasicPattern pattern, ExecutionContext execContext) {
+ return new QueryIterPropertyTable(input, pattern, execContext);
+ }
+
+ private QueryIterPropertyTable(QueryIterator input, BasicPattern pattern,
+ ExecutionContext execContext) {
+ super(input, execContext);
+ this.pattern = pattern;
+ graph = execContext.getActiveGraph();
+ // Create a chain of triple iterators.
+ QueryIterator chain = getInput();
+ Collection<BasicPattern> patterns = sort(pattern);
+ for (BasicPattern p : patterns)
+ chain = new QueryIterPropertyTableRow(chain, p, execContext);
+ output = chain;
+ }
+
+ private Collection<BasicPattern> sort(BasicPattern pattern) {
+ HashMap<Node, BasicPattern> map = new HashMap<Node, BasicPattern>();
+ for (Triple triple : pattern.getList()) {
+ Node subject = triple.getSubject();
+ if (!map.containsKey(subject)) {
+ List<Triple> triples = new ArrayList<Triple>();
+ BasicPattern p = BasicPattern.wrap(triples);
+ map.put(subject, p);
+ p.add(triple);
+ } else {
+ map.get(subject).add(triple);
+ }
+ }
+ return map.values();
+ }
+
+ @Override
+ protected boolean hasNextBinding() {
+ return output.hasNext();
+ }
+
+ @Override
+ protected Binding moveToNextBinding() {
+ return output.nextBinding();
+ }
+
+ @Override
+ protected void closeSubIterator() {
+ if (output != null)
+ output.close();
+ output = null;
+ }
+
+ @Override
+ protected void requestSubCancel() {
+ if (output != null)
+ output.cancel();
+ }
+
+ @Override
+ protected void details(IndentedWriter out, SerializationContext sCxt) {
+ out.print(Lib.className(this));
+ out.println();
+ out.incIndent();
+ FmtUtils.formatPattern(out, pattern, sCxt);
+ out.decIndent();
+ }
+}
http://git-wip-us.apache.org/repos/asf/jena/blob/d6ae87fd/jena-csv/src/main/java/org/apache/jena/propertytable/graph/QueryIterPropertyTableRow.java
----------------------------------------------------------------------
diff --git a/jena-csv/src/main/java/org/apache/jena/propertytable/graph/QueryIterPropertyTableRow.java b/jena-csv/src/main/java/org/apache/jena/propertytable/graph/QueryIterPropertyTableRow.java
index 8aeec57..3b28f24 100644
--- a/jena-csv/src/main/java/org/apache/jena/propertytable/graph/QueryIterPropertyTableRow.java
+++ b/jena-csv/src/main/java/org/apache/jena/propertytable/graph/QueryIterPropertyTableRow.java
@@ -1,243 +1,243 @@
-/*
- * 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.propertytable.graph;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.jena.graph.Node ;
-import org.apache.jena.graph.Triple ;
-import org.apache.jena.propertytable.PropertyTable;
-import org.apache.jena.propertytable.Row;
-
-
-import org.apache.jena.sparql.ARQInternalErrorException ;
-import org.apache.jena.sparql.core.BasicPattern ;
-import org.apache.jena.sparql.core.Var ;
-import org.apache.jena.sparql.engine.ExecutionContext ;
-import org.apache.jena.sparql.engine.QueryIterator ;
-import org.apache.jena.sparql.engine.binding.Binding ;
-import org.apache.jena.sparql.engine.binding.BindingFactory ;
-import org.apache.jena.sparql.engine.binding.BindingMap ;
-import org.apache.jena.sparql.engine.iterator.QueryIter ;
-import org.apache.jena.sparql.engine.iterator.QueryIterRepeatApply ;
-import org.apache.jena.util.iterator.ClosableIterator ;
-import org.apache.jena.util.iterator.ExtendedIterator ;
-import org.apache.jena.util.iterator.NiceIterator ;
-import org.apache.jena.util.iterator.WrappedIterator ;
-
-/**
- * If the triple size within a BasicePattern is greater than 1 (i.e. at least 2 triples), it's turned into a row querying.
- *
- */
-public class QueryIterPropertyTableRow extends QueryIterRepeatApply{
-
-
- private final BasicPattern pattern ;
-
- public QueryIterPropertyTableRow( QueryIterator input,
- BasicPattern pattern ,
- ExecutionContext cxt)
- {
- super(input, cxt) ;
- this.pattern = pattern ;
- }
-
- @Override
- protected QueryIterator nextStage(Binding binding)
- {
- return new RowMapper(binding, pattern, getExecContext()) ;
- }
-
- static int countMapper = 0 ;
- static class RowMapper extends QueryIter
- {
- private PropertyTable table;
-
- private BasicPattern pattern;
- private Binding binding ;
- private ClosableIterator<Row> graphIter ;
- private Binding slot = null ;
- private boolean finished = false ;
- private volatile boolean cancelled = false ;
-
- RowMapper(Binding binding, BasicPattern pattern, ExecutionContext cxt)
- {
- super(cxt) ;
- GraphPropertyTable graph = (GraphPropertyTable)cxt.getActiveGraph() ;
-
- this.pattern = substitute(pattern, binding);
- this.binding = binding ;
- BasicPattern pattern2 = tripleNode(pattern);
-
- ExtendedIterator<Row> iter = graph.propertyTableBaseFind( new RowMatch( pattern2) );
-
- if ( false )
- {
- // Materialize the results now. Debugging only.
- List<Row> x = iter.toList() ;
- this.graphIter = WrappedIterator.create(x.iterator()) ;
- iter.close();
- }
- else
- // Stream.
- this.graphIter = iter ;
- }
-
- private static Node tripleNode(Node node)
- {
- if ( node.isVariable() )
- return Node.ANY ;
- return node ;
- }
-
- private static BasicPattern tripleNode(BasicPattern pattern)
- {
- List<Triple> triples = new ArrayList<Triple>();
- for (Triple triple: pattern){
- triples.add( tripleNode(triple) );
- }
- return BasicPattern.wrap(triples);
- }
-
- private static Triple tripleNode(Triple triple){
- Node s = tripleNode(triple.getSubject()) ;
- Node p = tripleNode(triple.getPredicate()) ;
- Node o = tripleNode(triple.getObject()) ;
- return Triple.create(s, p, o);
- }
-
- private static Node substitute(Node node, Binding binding)
- {
- if ( Var.isVar(node) )
- {
- Node x = binding.get(Var.alloc(node)) ;
- if ( x != null )
- return x ;
- }
- return node ;
- }
-
- private static Triple substitute(Triple triple, Binding binding){
- Node s = substitute(triple.getSubject(), binding) ;
- Node p = substitute(triple.getPredicate(), binding) ;
- Node o = substitute(triple.getObject(), binding) ;
- return Triple.create(s, p, o);
- }
-
- private static BasicPattern substitute(BasicPattern pattern , Binding binding)
- {
- List<Triple> triples = new ArrayList<Triple>();
- for (Triple triple: pattern){
- triples.add( substitute(triple,binding) );
- }
- return BasicPattern.wrap(triples);
- }
-
- private Binding mapper(Row r)
- {
- BindingMap results = BindingFactory.create(binding) ;
-
- if ( ! insert(pattern, r, results) )
- return null ;
- return results ;
- }
-
- private static boolean insert(BasicPattern input, Row output, BindingMap results)
- {
- for (Triple triple: input){
- if (! insert(triple, output, results) ){
- return false;
- }
- }
- return true;
- }
-
- private static boolean insert(Triple input, Row output, BindingMap results){
- if ( ! insert(input.getSubject(), output.getRowKey(), results) )
- return false ;
-// if ( ! insert(input.getPredicate(), output.get, results) )
-// return false ;
- if ( ! insert(input.getObject(), output.getValue( input.getPredicate() ), results) )
- return false ;
- return true;
- }
-
- private static boolean insert(Node inputNode, Node outputNode, BindingMap results)
- {
- if ( ! Var.isVar(inputNode) )
- return true ;
-
- Var v = Var.alloc(inputNode) ;
- Node x = results.get(v) ;
- if ( x != null )
- return outputNode.equals(x) ;
-
- results.add(v, outputNode) ;
- return true ;
- }
-
- @Override
- protected boolean hasNextBinding()
- {
- if ( finished ) return false ;
- if ( slot != null ) return true ;
- if ( cancelled )
- {
- graphIter.close() ;
- finished = true ;
- return false ;
- }
-
- while(graphIter.hasNext() && slot == null )
- {
- Row r = graphIter.next() ;
- slot = mapper(r) ;
- }
- if ( slot == null )
- finished = true ;
- return slot != null ;
- }
-
- @Override
- protected Binding moveToNextBinding()
- {
- if ( ! hasNextBinding() )
- throw new ARQInternalErrorException() ;
- Binding r = slot ;
- slot = null ;
- return r ;
- }
-
- @Override
- protected void closeIterator()
- {
- if ( graphIter != null )
- NiceIterator.close(graphIter) ;
- graphIter = null ;
- }
-
- @Override
- protected void requestCancel()
- {
- // The QueryIteratorBase machinary will do the real work.
- cancelled = true ;
- }
- }
-}
+/*
+ * 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.propertytable.graph;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.jena.graph.Node ;
+import org.apache.jena.graph.Triple ;
+import org.apache.jena.propertytable.PropertyTable;
+import org.apache.jena.propertytable.Row;
+
+
+import org.apache.jena.sparql.ARQInternalErrorException ;
+import org.apache.jena.sparql.core.BasicPattern ;
+import org.apache.jena.sparql.core.Var ;
+import org.apache.jena.sparql.engine.ExecutionContext ;
+import org.apache.jena.sparql.engine.QueryIterator ;
+import org.apache.jena.sparql.engine.binding.Binding ;
+import org.apache.jena.sparql.engine.binding.BindingFactory ;
+import org.apache.jena.sparql.engine.binding.BindingMap ;
+import org.apache.jena.sparql.engine.iterator.QueryIter ;
+import org.apache.jena.sparql.engine.iterator.QueryIterRepeatApply ;
+import org.apache.jena.util.iterator.ClosableIterator ;
+import org.apache.jena.util.iterator.ExtendedIterator ;
+import org.apache.jena.util.iterator.NiceIterator ;
+import org.apache.jena.util.iterator.WrappedIterator ;
+
+/**
+ * If the triple size within a BasicePattern is greater than 1 (i.e. at least 2 triples), it's turned into a row querying.
+ *
+ */
+public class QueryIterPropertyTableRow extends QueryIterRepeatApply{
+
+
+ private final BasicPattern pattern ;
+
+ public QueryIterPropertyTableRow( QueryIterator input,
+ BasicPattern pattern ,
+ ExecutionContext cxt)
+ {
+ super(input, cxt) ;
+ this.pattern = pattern ;
+ }
+
+ @Override
+ protected QueryIterator nextStage(Binding binding)
+ {
+ return new RowMapper(binding, pattern, getExecContext()) ;
+ }
+
+ static int countMapper = 0 ;
+ static class RowMapper extends QueryIter
+ {
+ private PropertyTable table;
+
+ private BasicPattern pattern;
+ private Binding binding ;
+ private ClosableIterator<Row> graphIter ;
+ private Binding slot = null ;
+ private boolean finished = false ;
+ private volatile boolean cancelled = false ;
+
+ RowMapper(Binding binding, BasicPattern pattern, ExecutionContext cxt)
+ {
+ super(cxt) ;
+ GraphPropertyTable graph = (GraphPropertyTable)cxt.getActiveGraph() ;
+
+ this.pattern = substitute(pattern, binding);
+ this.binding = binding ;
+ BasicPattern pattern2 = tripleNode(pattern);
+
+ ExtendedIterator<Row> iter = graph.propertyTableBaseFind( new RowMatch( pattern2) );
+
+ if ( false )
+ {
+ // Materialize the results now. Debugging only.
+ List<Row> x = iter.toList() ;
+ this.graphIter = WrappedIterator.create(x.iterator()) ;
+ iter.close();
+ }
+ else
+ // Stream.
+ this.graphIter = iter ;
+ }
+
+ private static Node tripleNode(Node node)
+ {
+ if ( node.isVariable() )
+ return Node.ANY ;
+ return node ;
+ }
+
+ private static BasicPattern tripleNode(BasicPattern pattern)
+ {
+ List<Triple> triples = new ArrayList<Triple>();
+ for (Triple triple: pattern){
+ triples.add( tripleNode(triple) );
+ }
+ return BasicPattern.wrap(triples);
+ }
+
+ private static Triple tripleNode(Triple triple){
+ Node s = tripleNode(triple.getSubject()) ;
+ Node p = tripleNode(triple.getPredicate()) ;
+ Node o = tripleNode(triple.getObject()) ;
+ return Triple.create(s, p, o);
+ }
+
+ private static Node substitute(Node node, Binding binding)
+ {
+ if ( Var.isVar(node) )
+ {
+ Node x = binding.get(Var.alloc(node)) ;
+ if ( x != null )
+ return x ;
+ }
+ return node ;
+ }
+
+ private static Triple substitute(Triple triple, Binding binding){
+ Node s = substitute(triple.getSubject(), binding) ;
+ Node p = substitute(triple.getPredicate(), binding) ;
+ Node o = substitute(triple.getObject(), binding) ;
+ return Triple.create(s, p, o);
+ }
+
+ private static BasicPattern substitute(BasicPattern pattern , Binding binding)
+ {
+ List<Triple> triples = new ArrayList<Triple>();
+ for (Triple triple: pattern){
+ triples.add( substitute(triple,binding) );
+ }
+ return BasicPattern.wrap(triples);
+ }
+
+ private Binding mapper(Row r)
+ {
+ BindingMap results = BindingFactory.create(binding) ;
+
+ if ( ! insert(pattern, r, results) )
+ return null ;
+ return results ;
+ }
+
+ private static boolean insert(BasicPattern input, Row output, BindingMap results)
+ {
+ for (Triple triple: input){
+ if (! insert(triple, output, results) ){
+ return false;
+ }
+ }
+ return true;
+ }
+
+ private static boolean insert(Triple input, Row output, BindingMap results){
+ if ( ! insert(input.getSubject(), output.getRowKey(), results) )
+ return false ;
+// if ( ! insert(input.getPredicate(), output.get, results) )
+// return false ;
+ if ( ! insert(input.getObject(), output.getValue( input.getPredicate() ), results) )
+ return false ;
+ return true;
+ }
+
+ private static boolean insert(Node inputNode, Node outputNode, BindingMap results)
+ {
+ if ( ! Var.isVar(inputNode) )
+ return true ;
+
+ Var v = Var.alloc(inputNode) ;
+ Node x = results.get(v) ;
+ if ( x != null )
+ return outputNode.equals(x) ;
+
+ results.add(v, outputNode) ;
+ return true ;
+ }
+
+ @Override
+ protected boolean hasNextBinding()
+ {
+ if ( finished ) return false ;
+ if ( slot != null ) return true ;
+ if ( cancelled )
+ {
+ graphIter.close() ;
+ finished = true ;
+ return false ;
+ }
+
+ while(graphIter.hasNext() && slot == null )
+ {
+ Row r = graphIter.next() ;
+ slot = mapper(r) ;
+ }
+ if ( slot == null )
+ finished = true ;
+ return slot != null ;
+ }
+
+ @Override
+ protected Binding moveToNextBinding()
+ {
+ if ( ! hasNextBinding() )
+ throw new ARQInternalErrorException() ;
+ Binding r = slot ;
+ slot = null ;
+ return r ;
+ }
+
+ @Override
+ protected void closeIterator()
+ {
+ if ( graphIter != null )
+ NiceIterator.close(graphIter) ;
+ graphIter = null ;
+ }
+
+ @Override
+ protected void requestCancel()
+ {
+ // The QueryIteratorBase machinary will do the real work.
+ cancelled = true ;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/jena/blob/d6ae87fd/jena-csv/src/main/java/org/apache/jena/propertytable/graph/RowMatch.java
----------------------------------------------------------------------
diff --git a/jena-csv/src/main/java/org/apache/jena/propertytable/graph/RowMatch.java b/jena-csv/src/main/java/org/apache/jena/propertytable/graph/RowMatch.java
index 971438b..f5b9c18 100644
--- a/jena-csv/src/main/java/org/apache/jena/propertytable/graph/RowMatch.java
+++ b/jena-csv/src/main/java/org/apache/jena/propertytable/graph/RowMatch.java
@@ -1,48 +1,48 @@
-/*
- * 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.propertytable.graph;
-
-import org.apache.jena.graph.Node ;
-import org.apache.jena.sparql.core.BasicPattern ;
-
-/**
- * The data structure for matching a Row
- *
- */
-public class RowMatch {
-
- private BasicPattern pattern;
-
- public RowMatch( BasicPattern pattern ){
- this.pattern=pattern;
- }
-
- public Node getMatchSubject(){
- return pattern.get(0).getMatchSubject();
- }
-
- public Node getSubject(){
- return pattern.get(0).getSubject();
- }
-
- public BasicPattern getBasicPattern(){
- return pattern;
- }
-
-}
+/*
+ * 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.propertytable.graph;
+
+import org.apache.jena.graph.Node ;
+import org.apache.jena.sparql.core.BasicPattern ;
+
+/**
+ * The data structure for matching a Row
+ *
+ */
+public class RowMatch {
+
+ private BasicPattern pattern;
+
+ public RowMatch( BasicPattern pattern ){
+ this.pattern=pattern;
+ }
+
+ public Node getMatchSubject(){
+ return pattern.get(0).getMatchSubject();
+ }
+
+ public Node getSubject(){
+ return pattern.get(0).getSubject();
+ }
+
+ public BasicPattern getBasicPattern(){
+ return pattern;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/jena/blob/d6ae87fd/jena-csv/src/main/java/org/apache/jena/propertytable/graph/StageGeneratorPropertyTable.java
----------------------------------------------------------------------
diff --git a/jena-csv/src/main/java/org/apache/jena/propertytable/graph/StageGeneratorPropertyTable.java b/jena-csv/src/main/java/org/apache/jena/propertytable/graph/StageGeneratorPropertyTable.java
index 53df0c9..4692472 100644
--- a/jena-csv/src/main/java/org/apache/jena/propertytable/graph/StageGeneratorPropertyTable.java
+++ b/jena-csv/src/main/java/org/apache/jena/propertytable/graph/StageGeneratorPropertyTable.java
@@ -1,57 +1,57 @@
-/*
- * 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.propertytable.graph;
-
-
-import org.apache.jena.graph.Graph ;
-import org.apache.jena.sparql.core.BasicPattern ;
-import org.apache.jena.sparql.engine.ExecutionContext ;
-import org.apache.jena.sparql.engine.QueryIterator ;
-import org.apache.jena.sparql.engine.main.StageGenerator ;
-
-/**
- * The extension of StageGenerator for querying a Row.
- *
- */
-public class StageGeneratorPropertyTable implements StageGenerator {
-
- // Using OpExecutor is preferred.
- StageGenerator above = null ;
-
- public StageGeneratorPropertyTable(StageGenerator original)
- {
- above = original ;
- }
-
- @Override
- public QueryIterator execute(BasicPattern pattern, QueryIterator input, ExecutionContext execCxt)
- {
- // --- In case this isn't for GraphPropertyTable
- Graph g = execCxt.getActiveGraph() ;
-
- if ( ! ( g instanceof GraphPropertyTable ) )
- return above.execute(pattern, input, execCxt) ;
- if (pattern.size() <= 1){
- return above.execute(pattern, input, execCxt) ;
- }
- return QueryIterPropertyTable.create(input, pattern, execCxt);
- }
-
-
-}
+/*
+ * 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.propertytable.graph;
+
+
+import org.apache.jena.graph.Graph ;
+import org.apache.jena.sparql.core.BasicPattern ;
+import org.apache.jena.sparql.engine.ExecutionContext ;
+import org.apache.jena.sparql.engine.QueryIterator ;
+import org.apache.jena.sparql.engine.main.StageGenerator ;
+
+/**
+ * The extension of StageGenerator for querying a Row.
+ *
+ */
+public class StageGeneratorPropertyTable implements StageGenerator {
+
+ // Using OpExecutor is preferred.
+ StageGenerator above = null ;
+
+ public StageGeneratorPropertyTable(StageGenerator original)
+ {
+ above = original ;
+ }
+
+ @Override
+ public QueryIterator execute(BasicPattern pattern, QueryIterator input, ExecutionContext execCxt)
+ {
+ // --- In case this isn't for GraphPropertyTable
+ Graph g = execCxt.getActiveGraph() ;
+
+ if ( ! ( g instanceof GraphPropertyTable ) )
+ return above.execute(pattern, input, execCxt) ;
+ if (pattern.size() <= 1){
+ return above.execute(pattern, input, execCxt) ;
+ }
+ return QueryIterPropertyTable.create(input, pattern, execCxt);
+ }
+
+
+}
http://git-wip-us.apache.org/repos/asf/jena/blob/d6ae87fd/jena-csv/src/main/java/org/apache/jena/propertytable/impl/ColumnImpl.java
----------------------------------------------------------------------
diff --git a/jena-csv/src/main/java/org/apache/jena/propertytable/impl/ColumnImpl.java b/jena-csv/src/main/java/org/apache/jena/propertytable/impl/ColumnImpl.java
index 808441a..ce456f9 100644
--- a/jena-csv/src/main/java/org/apache/jena/propertytable/impl/ColumnImpl.java
+++ b/jena-csv/src/main/java/org/apache/jena/propertytable/impl/ColumnImpl.java
@@ -1,57 +1,57 @@
-/*
- * 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.propertytable.impl;
-
-
-import java.util.List;
-
-import org.apache.jena.graph.Node ;
-import org.apache.jena.propertytable.Column;
-import org.apache.jena.propertytable.PropertyTable;
-
-/**
- * The simple implementation of Column
- *
- */
-public class ColumnImpl implements Column {
-
-
- private final PropertyTable table;
- private Node p;
-
- ColumnImpl(PropertyTable table, Node p) {
- this.table = table;
- this.p = p;
- }
-
- @Override
- public PropertyTable getTable() {
- return table;
- }
-
- @Override
- public Node getColumnKey() {
- return p;
- }
-
- @Override
- public List<Node> getValues() {
- return table.getColumnValues(this);
- }
-}
+/*
+ * 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.propertytable.impl;
+
+
+import java.util.List;
+
+import org.apache.jena.graph.Node ;
+import org.apache.jena.propertytable.Column;
+import org.apache.jena.propertytable.PropertyTable;
+
+/**
+ * The simple implementation of Column
+ *
+ */
+public class ColumnImpl implements Column {
+
+
+ private final PropertyTable table;
+ private Node p;
+
+ ColumnImpl(PropertyTable table, Node p) {
+ this.table = table;
+ this.p = p;
+ }
+
+ @Override
+ public PropertyTable getTable() {
+ return table;
+ }
+
+ @Override
+ public Node getColumnKey() {
+ return p;
+ }
+
+ @Override
+ public List<Node> getValues() {
+ return table.getColumnValues(this);
+ }
+}
http://git-wip-us.apache.org/repos/asf/jena/blob/d6ae87fd/jena-csv/src/main/java/org/apache/jena/propertytable/impl/PropertyTableArrayImpl.java
----------------------------------------------------------------------
diff --git a/jena-csv/src/main/java/org/apache/jena/propertytable/impl/PropertyTableArrayImpl.java b/jena-csv/src/main/java/org/apache/jena/propertytable/impl/PropertyTableArrayImpl.java
index 6b8bd6e..1920045 100644
--- a/jena-csv/src/main/java/org/apache/jena/propertytable/impl/PropertyTableArrayImpl.java
+++ b/jena-csv/src/main/java/org/apache/jena/propertytable/impl/PropertyTableArrayImpl.java
@@ -1,345 +1,345 @@
-/*
- * 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.propertytable.impl;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.jena.atlas.iterator.Iter;
-import org.apache.jena.atlas.iterator.IteratorConcat;
-import org.apache.jena.graph.Node ;
-import org.apache.jena.graph.Triple ;
-import org.apache.jena.propertytable.Column;
-import org.apache.jena.propertytable.PropertyTable;
-import org.apache.jena.propertytable.Row;
-import org.apache.jena.util.iterator.ExtendedIterator ;
-import org.apache.jena.util.iterator.WrappedIterator ;
-
-/**
- * A PropertyTable Implementation using a two dimension array.
- * It contains SPO and PSO indexes.
- *
- */
-public class PropertyTableArrayImpl implements PropertyTable {
-
- private final List<Node> rowList;
- private final List<Node> columnList;
-
- private final Map<Node, Integer> rowKeyToIndex;
- private final Map<Node, Integer> columnKeyToIndex;
- private final Node[][] array;
- private final int rowNum;
- private final int columnNum;
-
- public PropertyTableArrayImpl(int rowNum, int columnNum){
- rowList = new ArrayList<Node>(rowNum);
- columnList = new ArrayList<Node>(columnNum);
- rowKeyToIndex = new HashMap<Node, Integer>();
- columnKeyToIndex = new HashMap<Node, Integer>();
- this.rowNum = rowNum;
- this.columnNum = columnNum;
- array = new Node [rowNum][columnNum];
- }
-
- @Override
- public ExtendedIterator<Triple> getTripleIterator(Column column, Node value) {
- if (column == null || column.getColumnKey() == null)
- throw new NullPointerException("column is null");
-
- if (value == null){
- throw new NullPointerException("value is null");
- }
-
- ArrayList<Triple> triples = new ArrayList<Triple>();
-
- Node p = column.getColumnKey();
- Integer columnIndex = this.columnKeyToIndex.get(p);
- if (columnIndex != null){
- for(int rowIndex=0; rowIndex< rowList.size();rowIndex++){
- if ( value.equals( this.get(rowIndex, columnIndex))){
- triples.add(Triple.create(rowList.get(rowIndex), p, value));
- }
- }
- }
- return WrappedIterator.create(triples.iterator());
- }
-
- @Override
- public ExtendedIterator<Triple> getTripleIterator(Column column) {
-
- if (column == null || column.getColumnKey() == null)
- throw new NullPointerException("column is null");
-
- ArrayList<Triple> triples = new ArrayList<Triple>();
-
- Node p = column.getColumnKey();
- Integer columnIndex = this.columnKeyToIndex.get(p);
- if (columnIndex != null){
- for(int rowIndex=0; rowIndex< rowList.size();rowIndex++){
- if(this.get(rowIndex, columnIndex)!=null){
- triples.add(Triple.create(rowList.get(rowIndex), p, this.get(rowIndex, columnIndex)));
- }
- }
- }
- return WrappedIterator.create(triples.iterator());
- }
-
- @Override
- public ExtendedIterator<Triple> getTripleIterator(Node value) {
- if (value == null)
- throw new NullPointerException("value is null");
-
- IteratorConcat<Triple> iter = new IteratorConcat<Triple>();
- for (Column column : this.getColumns()) {
- ExtendedIterator<Triple> eIter = getTripleIterator(column,value);
- iter.add(eIter);
- }
- return WrappedIterator.create(Iter.distinct(iter));
- }
-
- @Override
- public ExtendedIterator<Triple> getTripleIterator(Row row) {
- if (row == null || row.getRowKey() == null)
- throw new NullPointerException("row is null");
-
- ArrayList<Triple> triples = new ArrayList<Triple>();
- Integer rowIndex = this.rowKeyToIndex.get(row.getRowKey());
-
- if (rowIndex != null){
- for(int columnIndex=0; columnIndex < columnList.size(); columnIndex++){
- triples.add(Triple.create( row.getRowKey(), columnList.get(columnIndex), this.get(rowIndex, columnIndex)));
- }
- }
- return WrappedIterator.create(triples.iterator());
- }
-
- @Override
- public ExtendedIterator<Triple> getTripleIterator() {
-
- IteratorConcat<Triple> iter = new IteratorConcat<Triple>();
- for (Column column : getColumns()) {
- iter.add(getTripleIterator(column));
- }
- return WrappedIterator.create(Iter.distinct(iter));
- }
-
- @Override
- public Collection<Column> getColumns() {
- Collection<Column> columns = new ArrayList<Column>();
- for(Node p: columnKeyToIndex.keySet() ){
- columns.add(new ColumnImpl(this, p));
- }
- return columns;
- }
-
- @Override
- public Column getColumn(Node p) {
- if (p == null)
- throw new NullPointerException("column name is null");
- Integer columnIndex = columnKeyToIndex.get(p);
- return (columnIndex == null)
- ? null : new ColumnImpl(this, p);
- }
-
- @Override
- public Column createColumn(Node p) {
- if (p == null)
- throw new NullPointerException("column name is null");
-
- if (columnKeyToIndex.containsKey(p))
- throw new IllegalArgumentException("column already exists: '"
- + p.toString());
-
- if (columnList.size()>= columnNum)
- throw new IllegalArgumentException("cannot create new column for max column count: " + columnNum);
-
- columnList.add(p);
- columnKeyToIndex.put(p, columnList.indexOf(p));
- return getColumn(p);
- }
-
- @Override
- public Row getRow(Node s) {
- if (s == null)
- throw new NullPointerException("subject node is null");
-
- Integer rowIndex = rowKeyToIndex.get(s);
- return (rowIndex == null) ? null : new InternalRow(rowIndex);
- }
-
- @Override
- public Row createRow(Node s) {
- Row row = this.getRow(s);
- if (row != null)
- return row;
-
- if (rowList.size()>= rowNum)
- throw new IllegalArgumentException("cannot create new row for max row count: " + rowNum);
-
- rowList.add(s);
- int rowIndex = rowList.indexOf(s);
- rowKeyToIndex.put(s, rowIndex);
-
- return new InternalRow(rowIndex);
- }
-
- private void set(int rowIndex, int columnIndex, Node value) {
-
- if (rowIndex >= rowList.size())
- throw new IllegalArgumentException("row index out of bound: " + rowList.size());
- if (columnIndex >= columnList.size())
- throw new IllegalArgumentException("column index out of bound: " + columnList.size());
- array[rowIndex][columnIndex] = value;
- }
-
- public Node get(int rowIndex, int columnIndex) {
- if (rowIndex >= rowList.size())
- throw new IllegalArgumentException("row index out of bound: " + rowList.size());
- if (columnIndex >= columnList.size())
- throw new IllegalArgumentException("column index out of bound: " + columnList.size());
- return array[rowIndex][columnIndex];
- }
-
- @Override
- public List<Row> getAllRows() {
- ArrayList<Row> rows = new ArrayList<Row>();
- for (int rowIndex=0;rowIndex<rowList.size();rowIndex++){
- rows.add( new InternalRow(rowIndex));
- }
- return rows;
- }
-
- @Override
- public List<Node> getColumnValues(Column column) {
- if (column == null || column.getColumnKey() == null)
- throw new NullPointerException("column is null");
-
- Node p = column.getColumnKey();
- Integer columnIndex = this.columnKeyToIndex.get(p);
-
- List<Node> list = new ArrayList<Node>();
-
- if (columnIndex != null){
- for(int rowIndex=0; rowIndex< rowList.size();rowIndex++){
- if(this.get(rowIndex, columnIndex)!=null){
- list.add(this.get(rowIndex, columnIndex));
- }
- }
- }
- return list;
- }
-
-
- @Override
- public Collection<Row> getMatchingRows(Column column, Node value) {
-
- if (column == null || column.getColumnKey() == null)
- throw new NullPointerException("column is null");
-
- if (value == null){
- throw new NullPointerException("value is null");
- }
-
- final ArrayList<Row> matchingRows = new ArrayList<Row>();
-
- Node p = column.getColumnKey();
- Integer columnIndex = this.columnKeyToIndex.get(p);
- if (columnIndex != null){
- for(int rowIndex=0; rowIndex< rowList.size();rowIndex++){
- if ( value.equals( this.get(rowIndex, columnIndex))){
- matchingRows.add( this.getRow( rowList.get(rowIndex) ));
- }
- }
- }
- return matchingRows;
- }
-
- private final class InternalRow implements Row {
-
- final int rowIndex;
-
- InternalRow(int rowIndex) {
- this.rowIndex = rowIndex;
- }
-
- @Override
- public PropertyTable getTable() {
- return PropertyTableArrayImpl.this;
- }
-
- @Override
- public void setValue(Column column, Node value) {
- if (column == null || column.getColumnKey() == null)
- throw new NullPointerException("column is null");
-
- Integer columnIndex = columnKeyToIndex.get(column.getColumnKey());
- if (columnIndex == null)
- throw new IllegalArgumentException("column index does not exist: " + column.getColumnKey());
-
- set(rowIndex, columnIndex, value);
-
- }
-
- @Override
- public Node getValue(Column column) {
- if (column == null)
- throw new NullPointerException("column is null");
- return this.getValue(column.getColumnKey());
- }
-
- @Override
- public Node getValue(Node columnKey) {
- if (columnKey == null)
- throw new NullPointerException("column key is null");
-
- Integer columnIndex = columnKeyToIndex.get(columnKey);
- if (columnIndex == null)
- throw new IllegalArgumentException("column index does not exist: " + columnKey);
-
- return get(rowIndex, columnIndex);
- }
-
- @Override
- public Node getRowKey() {
- return rowList.get(rowIndex);
- }
-
- @Override
- public ExtendedIterator<Triple> getTripleIterator() {
- ArrayList<Triple> triples = new ArrayList<Triple>();
- for (int columnIndex=0;columnIndex<columnList.size();columnIndex++) {
- triples.add(Triple.create(getRowKey(), columnList.get(columnIndex), get(rowIndex, columnIndex)));
- }
- return WrappedIterator.create(triples.iterator());
- }
-
- @Override
- public Collection<Column> getColumns() {
- return PropertyTableArrayImpl.this.getColumns();
- }
-
- }
-
-
-
-
-}
+/*
+ * 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.propertytable.impl;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.jena.atlas.iterator.Iter;
+import org.apache.jena.atlas.iterator.IteratorConcat;
+import org.apache.jena.graph.Node ;
+import org.apache.jena.graph.Triple ;
+import org.apache.jena.propertytable.Column;
+import org.apache.jena.propertytable.PropertyTable;
+import org.apache.jena.propertytable.Row;
+import org.apache.jena.util.iterator.ExtendedIterator ;
+import org.apache.jena.util.iterator.WrappedIterator ;
+
+/**
+ * A PropertyTable Implementation using a two dimension array.
+ * It contains SPO and PSO indexes.
+ *
+ */
+public class PropertyTableArrayImpl implements PropertyTable {
+
+ private final List<Node> rowList;
+ private final List<Node> columnList;
+
+ private final Map<Node, Integer> rowKeyToIndex;
+ private final Map<Node, Integer> columnKeyToIndex;
+ private final Node[][] array;
+ private final int rowNum;
+ private final int columnNum;
+
+ public PropertyTableArrayImpl(int rowNum, int columnNum){
+ rowList = new ArrayList<Node>(rowNum);
+ columnList = new ArrayList<Node>(columnNum);
+ rowKeyToIndex = new HashMap<Node, Integer>();
+ columnKeyToIndex = new HashMap<Node, Integer>();
+ this.rowNum = rowNum;
+ this.columnNum = columnNum;
+ array = new Node [rowNum][columnNum];
+ }
+
+ @Override
+ public ExtendedIterator<Triple> getTripleIterator(Column column, Node value) {
+ if (column == null || column.getColumnKey() == null)
+ throw new NullPointerException("column is null");
+
+ if (value == null){
+ throw new NullPointerException("value is null");
+ }
+
+ ArrayList<Triple> triples = new ArrayList<Triple>();
+
+ Node p = column.getColumnKey();
+ Integer columnIndex = this.columnKeyToIndex.get(p);
+ if (columnIndex != null){
+ for(int rowIndex=0; rowIndex< rowList.size();rowIndex++){
+ if ( value.equals( this.get(rowIndex, columnIndex))){
+ triples.add(Triple.create(rowList.get(rowIndex), p, value));
+ }
+ }
+ }
+ return WrappedIterator.create(triples.iterator());
+ }
+
+ @Override
+ public ExtendedIterator<Triple> getTripleIterator(Column column) {
+
+ if (column == null || column.getColumnKey() == null)
+ throw new NullPointerException("column is null");
+
+ ArrayList<Triple> triples = new ArrayList<Triple>();
+
+ Node p = column.getColumnKey();
+ Integer columnIndex = this.columnKeyToIndex.get(p);
+ if (columnIndex != null){
+ for(int rowIndex=0; rowIndex< rowList.size();rowIndex++){
+ if(this.get(rowIndex, columnIndex)!=null){
+ triples.add(Triple.create(rowList.get(rowIndex), p, this.get(rowIndex, columnIndex)));
+ }
+ }
+ }
+ return WrappedIterator.create(triples.iterator());
+ }
+
+ @Override
+ public ExtendedIterator<Triple> getTripleIterator(Node value) {
+ if (value == null)
+ throw new NullPointerException("value is null");
+
+ IteratorConcat<Triple> iter = new IteratorConcat<Triple>();
+ for (Column column : this.getColumns()) {
+ ExtendedIterator<Triple> eIter = getTripleIterator(column,value);
+ iter.add(eIter);
+ }
+ return WrappedIterator.create(Iter.distinct(iter));
+ }
+
+ @Override
+ public ExtendedIterator<Triple> getTripleIterator(Row row) {
+ if (row == null || row.getRowKey() == null)
+ throw new NullPointerException("row is null");
+
+ ArrayList<Triple> triples = new ArrayList<Triple>();
+ Integer rowIndex = this.rowKeyToIndex.get(row.getRowKey());
+
+ if (rowIndex != null){
+ for(int columnIndex=0; columnIndex < columnList.size(); columnIndex++){
+ triples.add(Triple.create( row.getRowKey(), columnList.get(columnIndex), this.get(rowIndex, columnIndex)));
+ }
+ }
+ return WrappedIterator.create(triples.iterator());
+ }
+
+ @Override
+ public ExtendedIterator<Triple> getTripleIterator() {
+
+ IteratorConcat<Triple> iter = new IteratorConcat<Triple>();
+ for (Column column : getColumns()) {
+ iter.add(getTripleIterator(column));
+ }
+ return WrappedIterator.create(Iter.distinct(iter));
+ }
+
+ @Override
+ public Collection<Column> getColumns() {
+ Collection<Column> columns = new ArrayList<Column>();
+ for(Node p: columnKeyToIndex.keySet() ){
+ columns.add(new ColumnImpl(this, p));
+ }
+ return columns;
+ }
+
+ @Override
+ public Column getColumn(Node p) {
+ if (p == null)
+ throw new NullPointerException("column name is null");
+ Integer columnIndex = columnKeyToIndex.get(p);
+ return (columnIndex == null)
+ ? null : new ColumnImpl(this, p);
+ }
+
+ @Override
+ public Column createColumn(Node p) {
+ if (p == null)
+ throw new NullPointerException("column name is null");
+
+ if (columnKeyToIndex.containsKey(p))
+ throw new IllegalArgumentException("column already exists: '"
+ + p.toString());
+
+ if (columnList.size()>= columnNum)
+ throw new IllegalArgumentException("cannot create new column for max column count: " + columnNum);
+
+ columnList.add(p);
+ columnKeyToIndex.put(p, columnList.indexOf(p));
+ return getColumn(p);
+ }
+
+ @Override
+ public Row getRow(Node s) {
+ if (s == null)
+ throw new NullPointerException("subject node is null");
+
+ Integer rowIndex = rowKeyToIndex.get(s);
+ return (rowIndex == null) ? null : new InternalRow(rowIndex);
+ }
+
+ @Override
+ public Row createRow(Node s) {
+ Row row = this.getRow(s);
+ if (row != null)
+ return row;
+
+ if (rowList.size()>= rowNum)
+ throw new IllegalArgumentException("cannot create new row for max row count: " + rowNum);
+
+ rowList.add(s);
+ int rowIndex = rowList.indexOf(s);
+ rowKeyToIndex.put(s, rowIndex);
+
+ return new InternalRow(rowIndex);
+ }
+
+ private void set(int rowIndex, int columnIndex, Node value) {
+
+ if (rowIndex >= rowList.size())
+ throw new IllegalArgumentException("row index out of bound: " + rowList.size());
+ if (columnIndex >= columnList.size())
+ throw new IllegalArgumentException("column index out of bound: " + columnList.size());
+ array[rowIndex][columnIndex] = value;
+ }
+
+ public Node get(int rowIndex, int columnIndex) {
+ if (rowIndex >= rowList.size())
+ throw new IllegalArgumentException("row index out of bound: " + rowList.size());
+ if (columnIndex >= columnList.size())
+ throw new IllegalArgumentException("column index out of bound: " + columnList.size());
+ return array[rowIndex][columnIndex];
+ }
+
+ @Override
+ public List<Row> getAllRows() {
+ ArrayList<Row> rows = new ArrayList<Row>();
+ for (int rowIndex=0;rowIndex<rowList.size();rowIndex++){
+ rows.add( new InternalRow(rowIndex));
+ }
+ return rows;
+ }
+
+ @Override
+ public List<Node> getColumnValues(Column column) {
+ if (column == null || column.getColumnKey() == null)
+ throw new NullPointerException("column is null");
+
+ Node p = column.getColumnKey();
+ Integer columnIndex = this.columnKeyToIndex.get(p);
+
+ List<Node> list = new ArrayList<Node>();
+
+ if (columnIndex != null){
+ for(int rowIndex=0; rowIndex< rowList.size();rowIndex++){
+ if(this.get(rowIndex, columnIndex)!=null){
+ list.add(this.get(rowIndex, columnIndex));
+ }
+ }
+ }
+ return list;
+ }
+
+
+ @Override
+ public Collection<Row> getMatchingRows(Column column, Node value) {
+
+ if (column == null || column.getColumnKey() == null)
+ throw new NullPointerException("column is null");
+
+ if (value == null){
+ throw new NullPointerException("value is null");
+ }
+
+ final ArrayList<Row> matchingRows = new ArrayList<Row>();
+
+ Node p = column.getColumnKey();
+ Integer columnIndex = this.columnKeyToIndex.get(p);
+ if (columnIndex != null){
+ for(int rowIndex=0; rowIndex< rowList.size();rowIndex++){
+ if ( value.equals( this.get(rowIndex, columnIndex))){
+ matchingRows.add( this.getRow( rowList.get(rowIndex) ));
+ }
+ }
+ }
+ return matchingRows;
+ }
+
+ private final class InternalRow implements Row {
+
+ final int rowIndex;
+
+ InternalRow(int rowIndex) {
+ this.rowIndex = rowIndex;
+ }
+
+ @Override
+ public PropertyTable getTable() {
+ return PropertyTableArrayImpl.this;
+ }
+
+ @Override
+ public void setValue(Column column, Node value) {
+ if (column == null || column.getColumnKey() == null)
+ throw new NullPointerException("column is null");
+
+ Integer columnIndex = columnKeyToIndex.get(column.getColumnKey());
+ if (columnIndex == null)
+ throw new IllegalArgumentException("column index does not exist: " + column.getColumnKey());
+
+ set(rowIndex, columnIndex, value);
+
+ }
+
+ @Override
+ public Node getValue(Column column) {
+ if (column == null)
+ throw new NullPointerException("column is null");
+ return this.getValue(column.getColumnKey());
+ }
+
+ @Override
+ public Node getValue(Node columnKey) {
+ if (columnKey == null)
+ throw new NullPointerException("column key is null");
+
+ Integer columnIndex = columnKeyToIndex.get(columnKey);
+ if (columnIndex == null)
+ throw new IllegalArgumentException("column index does not exist: " + columnKey);
+
+ return get(rowIndex, columnIndex);
+ }
+
+ @Override
+ public Node getRowKey() {
+ return rowList.get(rowIndex);
+ }
+
+ @Override
+ public ExtendedIterator<Triple> getTripleIterator() {
+ ArrayList<Triple> triples = new ArrayList<Triple>();
+ for (int columnIndex=0;columnIndex<columnList.size();columnIndex++) {
+ triples.add(Triple.create(getRowKey(), columnList.get(columnIndex), get(rowIndex, columnIndex)));
+ }
+ return WrappedIterator.create(triples.iterator());
+ }
+
+ @Override
+ public Collection<Column> getColumns() {
+ return PropertyTableArrayImpl.this.getColumns();
+ }
+
+ }
+
+
+
+
+}
http://git-wip-us.apache.org/repos/asf/jena/blob/d6ae87fd/jena-csv/src/main/java/org/apache/jena/propertytable/impl/PropertyTableBuilder.java
----------------------------------------------------------------------
diff --git a/jena-csv/src/main/java/org/apache/jena/propertytable/impl/PropertyTableBuilder.java b/jena-csv/src/main/java/org/apache/jena/propertytable/impl/PropertyTableBuilder.java
index 0532dc9..a0c5af1 100644
--- a/jena-csv/src/main/java/org/apache/jena/propertytable/impl/PropertyTableBuilder.java
+++ b/jena-csv/src/main/java/org/apache/jena/propertytable/impl/PropertyTableBuilder.java
@@ -1,135 +1,135 @@
-/*
- * 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.propertytable.impl;
-
-import java.io.InputStream ;
-import java.util.ArrayList ;
-import java.util.Iterator ;
-import java.util.List ;
-
-import org.apache.jena.atlas.csv.CSVParser ;
-import org.apache.jena.atlas.io.IO ;
-import org.apache.jena.datatypes.xsd.XSDDatatype ;
-import org.apache.jena.graph.Node ;
-import org.apache.jena.graph.NodeFactory ;
-import org.apache.jena.propertytable.PropertyTable ;
-import org.apache.jena.propertytable.Row ;
-import org.apache.jena.propertytable.lang.LangCSV ;
-import org.apache.jena.riot.system.IRIResolver ;
-
-
-/**
- * A tool for constructing PropertyTable from a file (e.g., a CSV file).
- *
- *
- */
-public class PropertyTableBuilder {
-
- public static Node CSV_ROW_NODE = NodeFactory.createURI(LangCSV.CSV_ROW);
-
- public static PropertyTable buildPropetyTableHashMapImplFromCsv(String csvFilePath) {
- PropertyTable table = new PropertyTableHashMapImpl();
- return fillPropertyTable(table, csvFilePath);
- }
-
- public static PropertyTable buildPropetyTableArrayImplFromCsv(String csvFilePath) {
- PropertyTable table = createEmptyPropertyTableArrayImpl(csvFilePath);
- return fillPropertyTable(table, csvFilePath);
- }
-
- private static PropertyTable createEmptyPropertyTableArrayImpl (String csvFilePath) {
- CSVParser parser = CSVParser.create(csvFilePath);
- List<String> rowLine = null;
- int rowNum = 0;
- int columnNum = 0;
-
- while ((rowLine = parser.parse1()) != null) {
- if (rowNum == 0) {
- columnNum = rowLine.size();
- }
- rowNum++;
- }
- if (rowNum!=0 && columnNum!=0){
- return new PropertyTableArrayImpl(rowNum, columnNum+1);
- } else {
- return null;
- }
- }
-
- protected static PropertyTable fillPropertyTable(PropertyTable table, String csvFilePath ){
- InputStream input = IO.openFile(csvFilePath) ;
- CSVParser iterator = CSVParser.create(input) ;
- return fillPropertyTable(table, iterator, csvFilePath);
- }
-
- protected static PropertyTable fillPropertyTable(PropertyTable table, CSVParser parser, String csvFilePath){
- if (table == null){
- return null;
- }
- ArrayList<Node> predicates = new ArrayList<Node>();
- int rowNum = 0;
-
- Iterator<List<String>> iter = parser.iterator() ;
- if ( ! iter.hasNext() )
- return table ;
- List<String> row1 = iter.next() ;
- table.createColumn(CSV_ROW_NODE);
- for (String column : row1) {
- String uri = createColumnKeyURI(csvFilePath, column);
- Node p = NodeFactory.createURI(uri);
- predicates.add(p);
- table.createColumn(p);
- }
-
- rowNum++ ;
- while(iter.hasNext()) {
- List<String> rowLine = iter.next();
- Node subject = LangCSV.caculateSubject(rowNum, csvFilePath);
- Row row = table.createRow(subject);
-
- row.setValue(table.getColumn(CSV_ROW_NODE),
- NodeFactory.createLiteral((rowNum + ""), XSDDatatype.XSDinteger));
-
- for (int col = 0; col < rowLine.size() && col<predicates.size(); col++) {
-
- String columnValue = rowLine.get(col).trim();
- if("".equals(columnValue)){
- continue;
- }
- Node o;
- try {
- // Try for a double.
- double d = Double.parseDouble(columnValue);
- o = NodeFactory.createLiteral(columnValue,
- XSDDatatype.XSDdouble);
- } catch (Exception e) {
- o = NodeFactory.createLiteral(columnValue);
- }
- row.setValue(table.getColumn(predicates.get(col)), o);
- }
- rowNum++ ;
- }
- return table;
- }
-
- protected static String createColumnKeyURI(String csvFilePath, String column){
- String uri = IRIResolver.resolveString(csvFilePath) + "#" + LangCSV.toSafeLocalname(column);
- return uri;
- }
-}
+/*
+ * 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.propertytable.impl;
+
+import java.io.InputStream ;
+import java.util.ArrayList ;
+import java.util.Iterator ;
+import java.util.List ;
+
+import org.apache.jena.atlas.csv.CSVParser ;
+import org.apache.jena.atlas.io.IO ;
+import org.apache.jena.datatypes.xsd.XSDDatatype ;
+import org.apache.jena.graph.Node ;
+import org.apache.jena.graph.NodeFactory ;
+import org.apache.jena.propertytable.PropertyTable ;
+import org.apache.jena.propertytable.Row ;
+import org.apache.jena.propertytable.lang.LangCSV ;
+import org.apache.jena.riot.system.IRIResolver ;
+
+
+/**
+ * A tool for constructing PropertyTable from a file (e.g., a CSV file).
+ *
+ *
+ */
+public class PropertyTableBuilder {
+
+ public static Node CSV_ROW_NODE = NodeFactory.createURI(LangCSV.CSV_ROW);
+
+ public static PropertyTable buildPropetyTableHashMapImplFromCsv(String csvFilePath) {
+ PropertyTable table = new PropertyTableHashMapImpl();
+ return fillPropertyTable(table, csvFilePath);
+ }
+
+ public static PropertyTable buildPropetyTableArrayImplFromCsv(String csvFilePath) {
+ PropertyTable table = createEmptyPropertyTableArrayImpl(csvFilePath);
+ return fillPropertyTable(table, csvFilePath);
+ }
+
+ private static PropertyTable createEmptyPropertyTableArrayImpl (String csvFilePath) {
+ CSVParser parser = CSVParser.create(csvFilePath);
+ List<String> rowLine = null;
+ int rowNum = 0;
+ int columnNum = 0;
+
+ while ((rowLine = parser.parse1()) != null) {
+ if (rowNum == 0) {
+ columnNum = rowLine.size();
+ }
+ rowNum++;
+ }
+ if (rowNum!=0 && columnNum!=0){
+ return new PropertyTableArrayImpl(rowNum, columnNum+1);
+ } else {
+ return null;
+ }
+ }
+
+ protected static PropertyTable fillPropertyTable(PropertyTable table, String csvFilePath ){
+ InputStream input = IO.openFile(csvFilePath) ;
+ CSVParser iterator = CSVParser.create(input) ;
+ return fillPropertyTable(table, iterator, csvFilePath);
+ }
+
+ protected static PropertyTable fillPropertyTable(PropertyTable table, CSVParser parser, String csvFilePath){
+ if (table == null){
+ return null;
+ }
+ ArrayList<Node> predicates = new ArrayList<Node>();
+ int rowNum = 0;
+
+ Iterator<List<String>> iter = parser.iterator() ;
+ if ( ! iter.hasNext() )
+ return table ;
+ List<String> row1 = iter.next() ;
+ table.createColumn(CSV_ROW_NODE);
+ for (String column : row1) {
+ String uri = createColumnKeyURI(csvFilePath, column);
+ Node p = NodeFactory.createURI(uri);
+ predicates.add(p);
+ table.createColumn(p);
+ }
+
+ rowNum++ ;
+ while(iter.hasNext()) {
+ List<String> rowLine = iter.next();
+ Node subject = LangCSV.caculateSubject(rowNum, csvFilePath);
+ Row row = table.createRow(subject);
+
+ row.setValue(table.getColumn(CSV_ROW_NODE),
+ NodeFactory.createLiteral((rowNum + ""), XSDDatatype.XSDinteger));
+
+ for (int col = 0; col < rowLine.size() && col<predicates.size(); col++) {
+
+ String columnValue = rowLine.get(col).trim();
+ if("".equals(columnValue)){
+ continue;
+ }
+ Node o;
+ try {
+ // Try for a double.
+ double d = Double.parseDouble(columnValue);
+ o = NodeFactory.createLiteral(columnValue,
+ XSDDatatype.XSDdouble);
+ } catch (Exception e) {
+ o = NodeFactory.createLiteral(columnValue);
+ }
+ row.setValue(table.getColumn(predicates.get(col)), o);
+ }
+ rowNum++ ;
+ }
+ return table;
+ }
+
+ protected static String createColumnKeyURI(String csvFilePath, String column){
+ String uri = IRIResolver.resolveString(csvFilePath) + "#" + LangCSV.toSafeLocalname(column);
+ return uri;
+ }
+}