You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jena.apache.org by jp...@apache.org on 2014/06/07 15:03:07 UTC

svn commit: r1601104 - in /jena/Experimental/jena-csv: ./ src/main/java/com/ src/main/java/com/hp/ src/main/java/com/hp/hpl/ src/main/java/com/hp/hpl/jena/ src/main/java/com/hp/hpl/jena/propertytable/ src/main/java/com/hp/hpl/jena/propertytable/impl/ s...

Author: jpz6311whu
Date: Sat Jun  7 13:03:06 2014
New Revision: 1601104

URL: http://svn.apache.org/r1601104
Log:
JENA-625: Design and implement PropertyTable, GraphPropertyTable and GraphCSV with an illustrative test demo original from the project proposal.

Added:
    jena/Experimental/jena-csv/src/main/java/com/
    jena/Experimental/jena-csv/src/main/java/com/hp/
    jena/Experimental/jena-csv/src/main/java/com/hp/hpl/
    jena/Experimental/jena-csv/src/main/java/com/hp/hpl/jena/
    jena/Experimental/jena-csv/src/main/java/com/hp/hpl/jena/propertytable/
    jena/Experimental/jena-csv/src/main/java/com/hp/hpl/jena/propertytable/Column.java   (with props)
    jena/Experimental/jena-csv/src/main/java/com/hp/hpl/jena/propertytable/PropertyTable.java   (with props)
    jena/Experimental/jena-csv/src/main/java/com/hp/hpl/jena/propertytable/Row.java   (with props)
    jena/Experimental/jena-csv/src/main/java/com/hp/hpl/jena/propertytable/impl/
    jena/Experimental/jena-csv/src/main/java/com/hp/hpl/jena/propertytable/impl/ColumnImpl.java   (with props)
    jena/Experimental/jena-csv/src/main/java/com/hp/hpl/jena/propertytable/impl/GraphCSV.java   (with props)
    jena/Experimental/jena-csv/src/main/java/com/hp/hpl/jena/propertytable/impl/GraphPropertyTable.java   (with props)
    jena/Experimental/jena-csv/src/main/java/com/hp/hpl/jena/propertytable/impl/PropertyTableBuilder.java   (with props)
    jena/Experimental/jena-csv/src/main/java/com/hp/hpl/jena/propertytable/impl/PropertyTableImpl.java   (with props)
    jena/Experimental/jena-csv/src/test/java/com/
    jena/Experimental/jena-csv/src/test/java/com/hp/
    jena/Experimental/jena-csv/src/test/java/com/hp/hpl/
    jena/Experimental/jena-csv/src/test/java/com/hp/hpl/jena/
    jena/Experimental/jena-csv/src/test/java/com/hp/hpl/jena/propertytable/
    jena/Experimental/jena-csv/src/test/java/com/hp/hpl/jena/propertytable/impl/
    jena/Experimental/jena-csv/src/test/java/com/hp/hpl/jena/propertytable/impl/GraphCSVTest.java   (with props)
    jena/Experimental/jena-csv/src/test/resources/test.csv
Modified:
    jena/Experimental/jena-csv/pom.xml

Modified: jena/Experimental/jena-csv/pom.xml
URL: http://svn.apache.org/viewvc/jena/Experimental/jena-csv/pom.xml?rev=1601104&r1=1601103&r2=1601104&view=diff
==============================================================================
--- jena/Experimental/jena-csv/pom.xml (original)
+++ jena/Experimental/jena-csv/pom.xml Sat Jun  7 13:03:06 2014
@@ -60,7 +60,15 @@
       <classifier>tests</classifier>
       <scope>test</scope>
     </dependency>
+    
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <scope>test</scope>
+    </dependency>
   </dependencies>
+  
+  
 
   <build>
     <plugins>

Added: jena/Experimental/jena-csv/src/main/java/com/hp/hpl/jena/propertytable/Column.java
URL: http://svn.apache.org/viewvc/jena/Experimental/jena-csv/src/main/java/com/hp/hpl/jena/propertytable/Column.java?rev=1601104&view=auto
==============================================================================
--- jena/Experimental/jena-csv/src/main/java/com/hp/hpl/jena/propertytable/Column.java (added)
+++ jena/Experimental/jena-csv/src/main/java/com/hp/hpl/jena/propertytable/Column.java Sat Jun  7 13:03:06 2014
@@ -0,0 +1,28 @@
+/*
+ * 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 com.hp.hpl.jena.propertytable;
+
+import com.hp.hpl.jena.graph.Node;
+
+public interface Column {
+
+	PropertyTable getTable();
+
+	Node getNode();
+
+}

Propchange: jena/Experimental/jena-csv/src/main/java/com/hp/hpl/jena/propertytable/Column.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: jena/Experimental/jena-csv/src/main/java/com/hp/hpl/jena/propertytable/PropertyTable.java
URL: http://svn.apache.org/viewvc/jena/Experimental/jena-csv/src/main/java/com/hp/hpl/jena/propertytable/PropertyTable.java?rev=1601104&view=auto
==============================================================================
--- jena/Experimental/jena-csv/src/main/java/com/hp/hpl/jena/propertytable/PropertyTable.java (added)
+++ jena/Experimental/jena-csv/src/main/java/com/hp/hpl/jena/propertytable/PropertyTable.java Sat Jun  7 13:03:06 2014
@@ -0,0 +1,39 @@
+/*
+ * 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 com.hp.hpl.jena.propertytable;
+
+import java.util.Collection;
+
+import com.hp.hpl.jena.graph.Node;
+import com.hp.hpl.jena.graph.Triple;
+import com.hp.hpl.jena.util.iterator.ExtendedIterator;
+
+public interface PropertyTable {
+	
+	ExtendedIterator<Triple> getTripleIterator();
+
+	ExtendedIterator<Triple> getTripleIterator(Column column);
+
+	Collection<Column> getColumns();
+
+	Column getColumn(Node p);
+
+	void createColumn(Node p);
+
+	Row getRow(Object rowNum);
+}

Propchange: jena/Experimental/jena-csv/src/main/java/com/hp/hpl/jena/propertytable/PropertyTable.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: jena/Experimental/jena-csv/src/main/java/com/hp/hpl/jena/propertytable/Row.java
URL: http://svn.apache.org/viewvc/jena/Experimental/jena-csv/src/main/java/com/hp/hpl/jena/propertytable/Row.java?rev=1601104&view=auto
==============================================================================
--- jena/Experimental/jena-csv/src/main/java/com/hp/hpl/jena/propertytable/Row.java (added)
+++ jena/Experimental/jena-csv/src/main/java/com/hp/hpl/jena/propertytable/Row.java Sat Jun  7 13:03:06 2014
@@ -0,0 +1,27 @@
+/*
+ * 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 com.hp.hpl.jena.propertytable;
+
+import com.hp.hpl.jena.graph.Node;
+
+public interface Row {
+
+	void set(Node p, Node value);
+
+}

Propchange: jena/Experimental/jena-csv/src/main/java/com/hp/hpl/jena/propertytable/Row.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: jena/Experimental/jena-csv/src/main/java/com/hp/hpl/jena/propertytable/impl/ColumnImpl.java
URL: http://svn.apache.org/viewvc/jena/Experimental/jena-csv/src/main/java/com/hp/hpl/jena/propertytable/impl/ColumnImpl.java?rev=1601104&view=auto
==============================================================================
--- jena/Experimental/jena-csv/src/main/java/com/hp/hpl/jena/propertytable/impl/ColumnImpl.java (added)
+++ jena/Experimental/jena-csv/src/main/java/com/hp/hpl/jena/propertytable/impl/ColumnImpl.java Sat Jun  7 13:03:06 2014
@@ -0,0 +1,43 @@
+/*
+ * 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 com.hp.hpl.jena.propertytable.impl;
+
+import com.hp.hpl.jena.graph.Node;
+import com.hp.hpl.jena.propertytable.Column;
+import com.hp.hpl.jena.propertytable.PropertyTable;
+
+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 getNode() {
+		return p;
+	}
+}

Propchange: jena/Experimental/jena-csv/src/main/java/com/hp/hpl/jena/propertytable/impl/ColumnImpl.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: jena/Experimental/jena-csv/src/main/java/com/hp/hpl/jena/propertytable/impl/GraphCSV.java
URL: http://svn.apache.org/viewvc/jena/Experimental/jena-csv/src/main/java/com/hp/hpl/jena/propertytable/impl/GraphCSV.java?rev=1601104&view=auto
==============================================================================
--- jena/Experimental/jena-csv/src/main/java/com/hp/hpl/jena/propertytable/impl/GraphCSV.java (added)
+++ jena/Experimental/jena-csv/src/main/java/com/hp/hpl/jena/propertytable/impl/GraphCSV.java Sat Jun  7 13:03:06 2014
@@ -0,0 +1,26 @@
+/*
+ * 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 com.hp.hpl.jena.propertytable.impl;
+
+public class GraphCSV extends GraphPropertyTable {
+	
+	public GraphCSV(String csvFilePath){
+		super(PropertyTableBuilder.buildPropetyTableFromCSVFile(csvFilePath));
+	}
+}

Propchange: jena/Experimental/jena-csv/src/main/java/com/hp/hpl/jena/propertytable/impl/GraphCSV.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: jena/Experimental/jena-csv/src/main/java/com/hp/hpl/jena/propertytable/impl/GraphPropertyTable.java
URL: http://svn.apache.org/viewvc/jena/Experimental/jena-csv/src/main/java/com/hp/hpl/jena/propertytable/impl/GraphPropertyTable.java?rev=1601104&view=auto
==============================================================================
--- jena/Experimental/jena-csv/src/main/java/com/hp/hpl/jena/propertytable/impl/GraphPropertyTable.java (added)
+++ jena/Experimental/jena-csv/src/main/java/com/hp/hpl/jena/propertytable/impl/GraphPropertyTable.java Sat Jun  7 13:03:06 2014
@@ -0,0 +1,117 @@
+/*
+ * 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 com.hp.hpl.jena.propertytable.impl;
+
+import java.util.Locale;
+
+import com.hp.hpl.jena.graph.Node;
+import com.hp.hpl.jena.graph.NodeFactory;
+import com.hp.hpl.jena.graph.Triple;
+import com.hp.hpl.jena.graph.TripleMatch;
+import com.hp.hpl.jena.graph.impl.GraphBase;
+import com.hp.hpl.jena.propertytable.Column;
+import com.hp.hpl.jena.propertytable.PropertyTable;
+import com.hp.hpl.jena.util.iterator.ExtendedIterator;
+import com.hp.hpl.jena.util.iterator.Filter;
+import com.hp.hpl.jena.util.iterator.NullIterator;
+
+public class GraphPropertyTable extends GraphBase {
+
+	private PropertyTable pt;
+
+	public GraphPropertyTable(PropertyTable pt) {
+		this.pt = pt;
+	}
+
+	@Override
+	protected ExtendedIterator<Triple> graphBaseFind(TripleMatch m) {
+
+		if (this.pt == null) {
+			return NullIterator.instance();
+		}
+		
+		ExtendedIterator<Triple> iter= null;
+		Node p = m.getMatchPredicate();
+		
+		
+		if (p == null || p == Node.ANY) {
+			iter = pt.getTripleIterator();
+		} else {
+			Column column = this.pt.getColumn(p);
+			if (column !=null){
+				iter = pt.getTripleIterator();
+			}else {
+				return NullIterator.instance();
+			}
+		}
+		
+		return iter.filterKeep ( new TripleMatchFilterEquality( m.asTriple() ) );
+
+	}
+	
+	static class TripleMatchFilterEquality extends Filter<Triple>
+    {
+        final protected Triple tMatch;
+    
+        /** Creates new TripleMatchFilter */
+        public TripleMatchFilterEquality(Triple tMatch) 
+            { this.tMatch = tMatch; }
+        
+        @Override
+        public boolean accept(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 ; 
+    }
+
+}

Propchange: jena/Experimental/jena-csv/src/main/java/com/hp/hpl/jena/propertytable/impl/GraphPropertyTable.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: jena/Experimental/jena-csv/src/main/java/com/hp/hpl/jena/propertytable/impl/PropertyTableBuilder.java
URL: http://svn.apache.org/viewvc/jena/Experimental/jena-csv/src/main/java/com/hp/hpl/jena/propertytable/impl/PropertyTableBuilder.java?rev=1601104&view=auto
==============================================================================
--- jena/Experimental/jena-csv/src/main/java/com/hp/hpl/jena/propertytable/impl/PropertyTableBuilder.java (added)
+++ jena/Experimental/jena-csv/src/main/java/com/hp/hpl/jena/propertytable/impl/PropertyTableBuilder.java Sat Jun  7 13:03:06 2014
@@ -0,0 +1,78 @@
+/*
+ * 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 com.hp.hpl.jena.propertytable.impl;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.jena.atlas.csv.CSVParser;
+import org.apache.jena.riot.lang.LangCSV;
+
+import com.hp.hpl.jena.datatypes.xsd.XSDDatatype;
+import com.hp.hpl.jena.graph.Node;
+import com.hp.hpl.jena.graph.NodeFactory;
+import com.hp.hpl.jena.propertytable.PropertyTable;
+import com.hp.hpl.jena.propertytable.Row;
+import com.hp.hpl.jena.util.FileUtils;
+
+public class PropertyTableBuilder {
+	
+	
+	public static Node CSV_ROW_NODE = NodeFactory.createURI(LangCSV.CSV_ROW);
+	
+	public static PropertyTable buildPropetyTableFromCSVFile(String csvFilePath){
+
+		CSVParser parser = CSVParser.create(csvFilePath);
+		PropertyTableImpl table = new PropertyTableImpl();
+		
+		List<String> rowLine = null ;
+		ArrayList<Node> predicates = new ArrayList<Node>();
+		int rowNum = 0;
+		
+		while ( (rowLine=parser.parse1())!=null) {
+			 if (rowNum==0){
+				 table.createColumn(CSV_ROW_NODE);
+				 for (String column: rowLine){
+					 Node p = NodeFactory.createURI(FileUtils.toURL(csvFilePath) + "#" + column.trim());
+					 predicates.add(p);
+					 table.createColumn(p);
+				 }
+			 }else {
+				 Row row = table.getRow(rowNum);
+				 row.set(CSV_ROW_NODE, NodeFactory.createLiteral( (rowNum+"").trim(), XSDDatatype.XSDinteger) );
+			 
+				 for (int col=0;col<rowLine.size();col++){
+					 
+					 String columnValue = rowLine.get(col).trim();
+					 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.set( predicates.get(col) , o);
+				 }
+			 }
+			 rowNum++;
+		}
+		return table;
+	}	
+}

Propchange: jena/Experimental/jena-csv/src/main/java/com/hp/hpl/jena/propertytable/impl/PropertyTableBuilder.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: jena/Experimental/jena-csv/src/main/java/com/hp/hpl/jena/propertytable/impl/PropertyTableImpl.java
URL: http://svn.apache.org/viewvc/jena/Experimental/jena-csv/src/main/java/com/hp/hpl/jena/propertytable/impl/PropertyTableImpl.java?rev=1601104&view=auto
==============================================================================
--- jena/Experimental/jena-csv/src/main/java/com/hp/hpl/jena/propertytable/impl/PropertyTableImpl.java (added)
+++ jena/Experimental/jena-csv/src/main/java/com/hp/hpl/jena/propertytable/impl/PropertyTableImpl.java Sat Jun  7 13:03:06 2014
@@ -0,0 +1,167 @@
+/*
+ * 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 com.hp.hpl.jena.propertytable.impl;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+
+import org.apache.jena.atlas.iterator.Iter;
+import org.apache.jena.atlas.iterator.IteratorConcat;
+
+import com.hp.hpl.jena.graph.Node;
+import com.hp.hpl.jena.graph.NodeFactory;
+import com.hp.hpl.jena.graph.Triple;
+import com.hp.hpl.jena.propertytable.Column;
+import com.hp.hpl.jena.propertytable.PropertyTable;
+import com.hp.hpl.jena.propertytable.Row;
+import com.hp.hpl.jena.rdf.model.AnonId;
+import com.hp.hpl.jena.util.iterator.ExtendedIterator;
+import com.hp.hpl.jena.util.iterator.WrappedIterator;
+
+public class PropertyTableImpl implements PropertyTable {
+
+	private Map<Node, Column> columnIndex; // Maps property Node to Column
+	private List<Column> columnList; // Stores the list of columns in the table
+	private Map<Object, Row> rowIndex; // Maps the row number to Row.
+	private List<Row> rowList; // Stores the list of rows in the table
+	private Map<Node, Map<Object, Node>> valueIndex; // Maps column Node to
+														// (rowNum,value) pairs
+
+	PropertyTableImpl() {
+		columnIndex = new HashMap<Node, Column>();
+		columnList = new ArrayList<Column>();
+		rowIndex = new HashMap<Object, Row>();
+		rowList = new ArrayList<Row>();
+		valueIndex = new HashMap<Node, Map<Object, Node>>();
+	}
+
+	@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 ExtendedIterator<Triple> getTripleIterator(Column column) {
+		ArrayList<Triple> triples = new ArrayList<Triple>();
+		Map<Object, Node> values = valueIndex.get(column.getNode());
+		
+		for(Entry<Object,Node> entry :values.entrySet()){
+			
+			Object rowNum = entry.getKey();
+			Node s  = NodeFactory.createAnon(AnonId.create( "_:"+rowNum  ));
+			Node value = entry.getValue();
+			triples.add( Triple.create(s, column.getNode(), value) );
+		}
+		return WrappedIterator.create(triples.iterator());
+	}
+
+	@Override
+	public Collection<Column> getColumns() {
+		return columnList;
+	}
+
+	@Override
+	public Column getColumn(Node p) {
+		return columnIndex.get(p);
+	}
+
+	@Override
+	public void createColumn(Node p) {
+		if (p == null)
+			throw new NullPointerException("column name is null");
+
+		if (columnIndex.containsKey(p))
+			throw new IllegalArgumentException("column already exists: '"
+					+ p.toString());
+
+		columnIndex.put(p, new ColumnImpl(this, p));
+		columnList.add(columnIndex.get(p));
+		valueIndex.put(p, new HashMap<Object, Node>());
+	}
+
+	@Override
+	public Row getRow(final Object rowNum) {
+		if (rowNum == null)
+			throw new NullPointerException("row number is null");
+		Row row = rowIndex.get(rowNum);
+		if (row != null)
+			return row;
+
+		row = new InternalRow(rowNum);
+		rowIndex.put(rowNum, row);
+		rowList.add(row);
+
+		return row;
+	}
+
+	private final void setX(final Object rowNum, final Node p, final Node value) {
+		if (p == null)
+			throw new NullPointerException("column Node must not be null.");
+		if (value == null)
+			throw new NullPointerException("value must not be null.");
+
+		if (columnIndex.get(p) == null)
+			throw new IllegalArgumentException("column: '" + p
+					+ "' does not yet exist.");
+
+		Map<Object, Node> rowNumToValueMap = valueIndex.get(p);
+		
+		rowNumToValueMap.put(rowNum, value);
+		
+	}
+
+	private void unSetX(final Object rowNum, final Node p) {
+
+		final Map<Object, Node> rowNumToValueMap = valueIndex.get(p);
+		if (!columnIndex.containsKey(p) || rowNumToValueMap == null)
+			throw new IllegalArgumentException("column: '" + p
+					+ "' does not yet exist.");
+
+		final Object value = rowNumToValueMap.get(rowNum);
+		if (value == null)
+			return;
+		
+		rowNumToValueMap.remove(rowNum);
+
+	}
+
+	private final class InternalRow implements Row {
+		private final Object key;
+
+		InternalRow(final Object key) {
+			this.key = key;
+		}
+
+		@Override
+		public void set(Node p, Node value) {
+			if (value == null)
+				unSetX(key, p);
+			else
+				setX(key, p, value);
+		}
+	}
+}

Propchange: jena/Experimental/jena-csv/src/main/java/com/hp/hpl/jena/propertytable/impl/PropertyTableImpl.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: jena/Experimental/jena-csv/src/test/java/com/hp/hpl/jena/propertytable/impl/GraphCSVTest.java
URL: http://svn.apache.org/viewvc/jena/Experimental/jena-csv/src/test/java/com/hp/hpl/jena/propertytable/impl/GraphCSVTest.java?rev=1601104&view=auto
==============================================================================
--- jena/Experimental/jena-csv/src/test/java/com/hp/hpl/jena/propertytable/impl/GraphCSVTest.java (added)
+++ jena/Experimental/jena-csv/src/test/java/com/hp/hpl/jena/propertytable/impl/GraphCSVTest.java Sat Jun  7 13:03:06 2014
@@ -0,0 +1,54 @@
+package com.hp.hpl.jena.propertytable.impl;
+/*
+ * 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.
+ */
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import com.hp.hpl.jena.propertytable.impl.GraphCSV;
+import com.hp.hpl.jena.query.Query;
+import com.hp.hpl.jena.query.QueryExecution;
+import com.hp.hpl.jena.query.QueryExecutionFactory;
+import com.hp.hpl.jena.query.QueryFactory;
+import com.hp.hpl.jena.query.QuerySolution;
+import com.hp.hpl.jena.query.ResultSet;
+import com.hp.hpl.jena.rdf.model.Model;
+import com.hp.hpl.jena.rdf.model.ModelFactory;
+
+public class GraphCSVTest extends Assert {
+	
+	@Test
+	public void testGraphCSV() throws Exception {
+		String file = "src/test/resources/test.csv";
+		
+		Model csv = ModelFactory.createModelForGraph(new GraphCSV(file));
+		assertEquals(6, csv.size());
+
+		Query query = QueryFactory
+				.create("PREFIX : <src/test/resources/test.csv#> SELECT ?townName ?pop {?x :Town ?townName ; :Population ?pop . FILTER(?pop > 500000)}");
+		QueryExecution qexec = QueryExecutionFactory.create(query, csv);
+		ResultSet results = qexec.execSelect();
+		
+		assertTrue(results.hasNext());
+		QuerySolution soln = results.nextSolution();
+		assertEquals( "Northville", soln.getLiteral("townName").getString());
+		assertTrue( 654000 == soln.getLiteral("pop").getInt());
+		
+		assertFalse(results.hasNext());
+	}
+}

Propchange: jena/Experimental/jena-csv/src/test/java/com/hp/hpl/jena/propertytable/impl/GraphCSVTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: jena/Experimental/jena-csv/src/test/resources/test.csv
URL: http://svn.apache.org/viewvc/jena/Experimental/jena-csv/src/test/resources/test.csv?rev=1601104&view=auto
==============================================================================
--- jena/Experimental/jena-csv/src/test/resources/test.csv (added)
+++ jena/Experimental/jena-csv/src/test/resources/test.csv Sat Jun  7 13:03:06 2014
@@ -0,0 +1,3 @@
+Town,Population
+Southton,123000.0 
+Northville,654000