jena-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rve...@apache.org
Subject [06/50] [abbrv] git commit: Add the implementation of PropertyTable with a two dimension array
Date Thu, 02 Oct 2014 09:48:15 GMT
Add the implementation of PropertyTable with a two dimension array

git-svn-id: http://svn.apache.org/repos/asf/jena/Experimental/jena-csv@1611267 13f79535-47bb-0310-9956-ffa450edef68


Project: http://git-wip-us.apache.org/repos/asf/jena/repo
Commit: http://git-wip-us.apache.org/repos/asf/jena/commit/517da327
Tree: http://git-wip-us.apache.org/repos/asf/jena/tree/517da327
Diff: http://git-wip-us.apache.org/repos/asf/jena/diff/517da327

Branch: refs/heads/jena-csv
Commit: 517da3276315b75821b64a1e23aacbc4720f5511
Parents: 2314299
Author: Ying Jiang <jpz6311whu@apache.org>
Authored: Thu Jul 17 07:24:21 2014 +0000
Committer: Ying Jiang <jpz6311whu@apache.org>
Committed: Thu Jul 17 07:24:21 2014 +0000

----------------------------------------------------------------------
 .../hpl/jena/propertytable/impl/GraphCSV.java   |  31 +-
 .../impl/PropertyTableArrayImpl.java            | 272 ++++++++++++++++
 .../impl/PropertyTableBuilder.java              |  39 ++-
 .../impl/PropertyTableHashMapImpl.java          | 323 +++++++++++++++++++
 .../propertytable/impl/PropertyTableImpl.java   | 301 -----------------
 .../jena/propertytable/impl/GraphCSVTest.java   |   2 +-
 6 files changed, 659 insertions(+), 309 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jena/blob/517da327/src/main/java/com/hp/hpl/jena/propertytable/impl/GraphCSV.java
----------------------------------------------------------------------
diff --git a/src/main/java/com/hp/hpl/jena/propertytable/impl/GraphCSV.java b/src/main/java/com/hp/hpl/jena/propertytable/impl/GraphCSV.java
index 7956985..d8ef46f 100644
--- a/src/main/java/com/hp/hpl/jena/propertytable/impl/GraphCSV.java
+++ b/src/main/java/com/hp/hpl/jena/propertytable/impl/GraphCSV.java
@@ -18,9 +18,36 @@
 
 package com.hp.hpl.jena.propertytable.impl;
 
+import com.hp.hpl.jena.propertytable.PropertyTable;
+
 public class GraphCSV extends GraphPropertyTable {
 	
-	public GraphCSV(String csvFilePath){
-		super(PropertyTableBuilder.buildPropetyTableFromCSVFile(csvFilePath));
+	public static GraphCSV createHashMapImpl( String csvFilePath ){
+		return new GraphCSVHashMapImpl(csvFilePath);
+	}
+	
+	public static GraphCSV createArrayImpl( String csvFilePath ){
+		return new GraphCSVArrayImpl(csvFilePath);
+	}
+	
+	protected GraphCSV (PropertyTable table) {
+		super(table);
+	}
+	
+	public GraphCSV ( String csvFilePath ){
+		super(PropertyTableBuilder.buildPropetyTableArrayImplFromCsv(csvFilePath));
+	}
+}
+
+
+class GraphCSVHashMapImpl extends GraphCSV{
+	protected GraphCSVHashMapImpl(String csvFilePath){
+		super(PropertyTableBuilder.buildPropetyTableHashMapImplFromCsv(csvFilePath));
+	}
+}
+
+class GraphCSVArrayImpl extends GraphCSV{
+	protected GraphCSVArrayImpl(String csvFilePath){
+		super(PropertyTableBuilder.buildPropetyTableArrayImplFromCsv(csvFilePath));
 	}
 }

http://git-wip-us.apache.org/repos/asf/jena/blob/517da327/src/main/java/com/hp/hpl/jena/propertytable/impl/PropertyTableArrayImpl.java
----------------------------------------------------------------------
diff --git a/src/main/java/com/hp/hpl/jena/propertytable/impl/PropertyTableArrayImpl.java
b/src/main/java/com/hp/hpl/jena/propertytable/impl/PropertyTableArrayImpl.java
new file mode 100644
index 0000000..3bcc8ba
--- /dev/null
+++ b/src/main/java/com/hp/hpl/jena/propertytable/impl/PropertyTableArrayImpl.java
@@ -0,0 +1,272 @@
+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 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.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.util.iterator.ExtendedIterator;
+import com.hp.hpl.jena.util.iterator.WrappedIterator;
+
+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++){
+				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 void 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));
+	}
+
+	@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 ExtendedIterator<Row> getRowIterator() {
+		ArrayList<Row> rows = new ArrayList<Row>();
+		for (int rowIndex=0;rowIndex<rowList.size();rowIndex++){
+			rows.add( new InternalRow(rowIndex));
+		}
+		return WrappedIterator.create(rows.iterator());
+	}
+	
+	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/517da327/src/main/java/com/hp/hpl/jena/propertytable/impl/PropertyTableBuilder.java
----------------------------------------------------------------------
diff --git a/src/main/java/com/hp/hpl/jena/propertytable/impl/PropertyTableBuilder.java b/src/main/java/com/hp/hpl/jena/propertytable/impl/PropertyTableBuilder.java
index 2df6c69..3dacf14 100644
--- a/src/main/java/com/hp/hpl/jena/propertytable/impl/PropertyTableBuilder.java
+++ b/src/main/java/com/hp/hpl/jena/propertytable/impl/PropertyTableBuilder.java
@@ -30,17 +30,46 @@ 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) {
-
+	
+	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);
-		PropertyTableImpl table = new PropertyTableImpl();
+		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;
+		}
+	}
 
+	
+	private static PropertyTable fillPropertyTable(PropertyTable table, String csvFilePath ){
+		if (table == null){
+			return null;
+		}
+		CSVParser parser = CSVParser.create(csvFilePath);
 		List<String> rowLine = null;
 		ArrayList<Node> predicates = new ArrayList<Node>();
 		int rowNum = 0;

http://git-wip-us.apache.org/repos/asf/jena/blob/517da327/src/main/java/com/hp/hpl/jena/propertytable/impl/PropertyTableHashMapImpl.java
----------------------------------------------------------------------
diff --git a/src/main/java/com/hp/hpl/jena/propertytable/impl/PropertyTableHashMapImpl.java
b/src/main/java/com/hp/hpl/jena/propertytable/impl/PropertyTableHashMapImpl.java
new file mode 100644
index 0000000..9ad261c
--- /dev/null
+++ b/src/main/java/com/hp/hpl/jena/propertytable/impl/PropertyTableHashMapImpl.java
@@ -0,0 +1,323 @@
+/*
+ * 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 java.util.Set;
+
+import org.apache.jena.atlas.iterator.Iter;
+import org.apache.jena.atlas.iterator.IteratorConcat;
+
+import com.google.common.collect.HashMultimap;
+import com.google.common.collect.SetMultimap;
+import com.hp.hpl.jena.graph.Node;
+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.util.iterator.ExtendedIterator;
+import com.hp.hpl.jena.util.iterator.WrappedIterator;
+
+/**
+ * A PropertyTable Implementation using HashMap.
+ * It contains PSO and POS indexes.
+ * 
+ */
+public class PropertyTableHashMapImpl implements PropertyTable {
+
+	private Map<Node, Column> columnIndex; // Maps property Node key to Column
+	private List<Column> columnList; // Stores the list of columns in the table
+	private Map<Node, Row> rowIndex; // Maps the subject Node key to Row.
+	private List<Row> rowList; // Stores the list of rows in the table
+
+	// PSO index
+	private Map<Node, Map<Node, Node>> valueIndex; // Maps column Node to
+													// (subject Node, value)
+													// pairs
+	// POS index
+	private Map<Node, SetMultimap<Node, Node>> valueReverseIndex; // Maps column
+																	// Node to
+																	// (value,
+																	// subject
+																	// Node)
+																	// pairs
+
+	PropertyTableHashMapImpl() {
+		columnIndex = new HashMap<Node, Column>();
+		columnList = new ArrayList<Column>();
+		rowIndex = new HashMap<Node, Row>();
+		rowList = new ArrayList<Row>();
+		valueIndex = new HashMap<Node, Map<Node, Node>>();
+		valueReverseIndex = new HashMap<Node, SetMultimap<Node, Node>>();
+	}
+
+	@Override
+	public ExtendedIterator<Triple> getTripleIterator() {
+		
+		// use PSO index to scan all the table (slow)
+		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) {
+		
+		// use PSO index directly (fast)
+		
+		if (column == null || column.getColumnKey() == null)
+			throw new NullPointerException("column is null");
+		
+		ArrayList<Triple> triples = new ArrayList<Triple>();
+		Map<Node, Node> values = valueIndex.get(column.getColumnKey());
+
+		for (Entry<Node, Node> entry : values.entrySet()) {
+			Node subject = entry.getKey();
+			Node value = entry.getValue();
+			triples.add(Triple.create(subject, column.getColumnKey(), value));
+		}
+		return WrappedIterator.create(triples.iterator());
+	}
+
+	@Override
+	public ExtendedIterator<Triple> getTripleIterator(Node value) {
+		
+		// use POS index ( O(n), n= column count )
+		
+		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(Column column, Node value) {
+		
+		// use POS index directly (fast)
+		
+		if (column == null || column.getColumnKey() == null)
+			throw new NullPointerException("column is null");
+		
+		if (value == null)
+			throw new NullPointerException("value is null");
+		
+		
+		Node p = column.getColumnKey();
+		final SetMultimap<Node, Node> valueToSubjectMap = valueReverseIndex
+				.get(p);
+		final Set<Node> subjects = valueToSubjectMap.get(value);
+		ArrayList<Triple> triples = new ArrayList<Triple>();
+		for (Node subject : subjects) {
+			triples.add(Triple.create(subject, p, value));
+		}
+		return WrappedIterator.create(triples.iterator());
+	}
+
+
+	@Override
+	public ExtendedIterator<Triple> getTripleIterator(Row row) {
+		// use PSO index ( O(n), n= column count )
+		
+		if (row == null || row.getRowKey() == null)
+			throw new NullPointerException("row is null");
+		
+		ArrayList<Triple> triples = new ArrayList<Triple>();
+		for (Column column : getColumns()) {
+			Node value = row.getValue(column);
+			triples.add(Triple.create(row.getRowKey(), column.getColumnKey(), value));
+		}
+		return WrappedIterator.create(triples.iterator());
+	}
+
+	@Override
+	public Collection<Column> getColumns() {
+		return columnList;
+	}
+
+	@Override
+	public Column getColumn(Node p) {
+		if (p == null)
+			throw new NullPointerException("column node is null");
+		return columnIndex.get(p);
+	}
+
+	@Override
+	public void createColumn(Node p) {
+		if (p == null)
+			throw new NullPointerException("column node 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<Node, Node>());
+		valueReverseIndex.put(p, HashMultimap.<Node, Node> create());
+	}
+
+	@Override
+	public Row getRow(final Node s) {
+		if (s == null)
+			throw new NullPointerException("subject node is null");
+		Row row = rowIndex.get(s);
+		return row;
+
+	}
+	
+	@Override
+	public Row createRow(final Node s){
+		Row row = this.getRow(s);
+		if (row != null)
+			return row;
+
+		row = new InternalRow(s);
+		rowIndex.put(s, row);
+		rowList.add(row);
+
+		return row;
+	}
+	
+	@Override
+	public ExtendedIterator<Row> getRowIterator() {
+		return WrappedIterator.create(rowList.iterator());
+	}
+
+	private final void setX(final Node s, 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.");
+
+		Map<Node, Node> subjectToValueMap = valueIndex.get(p);
+		if (!columnIndex.containsKey(p) || subjectToValueMap == null)
+			throw new IllegalArgumentException("column: '" + p
+					+ "' does not yet exist.");
+
+		Node oldValue = subjectToValueMap.get(s);
+		subjectToValueMap.put(s, value);
+		addToReverseMap(p, s, oldValue, value);
+	}
+
+	private void addToReverseMap(final Node p, final Node s,
+			final Node oldValue, final Node value) {
+
+		final SetMultimap<Node, Node> valueToSubjectMap = valueReverseIndex
+				.get(p);
+		valueToSubjectMap.remove(oldValue, s);
+		valueToSubjectMap.put(value, s);
+	}
+
+	private void unSetX(final Node s, final Node p) {
+
+		final Map<Node, Node> subjectToValueMap = valueIndex.get(p);
+		if (!columnIndex.containsKey(p) || subjectToValueMap == null)
+			throw new IllegalArgumentException("column: '" + p
+					+ "' does not yet exist.");
+
+		final Node value = subjectToValueMap.get(s);
+		if (value == null)
+			return;
+
+		subjectToValueMap.remove(s);
+		removeFromReverseMap(p, s, value);
+	}
+
+	private void removeFromReverseMap(final Node p, final Node s,
+			final Node value) {
+		final SetMultimap<Node, Node> valueTokeysMap = valueReverseIndex.get(p);
+		valueTokeysMap.remove(s, value);
+	}
+
+	private Node getX(final Node s, final Node p) {
+		final Map<Node, Node> subjectToValueMap = valueIndex.get(p);
+		if (!columnIndex.containsKey(p) || subjectToValueMap == null)
+			throw new IllegalArgumentException("column: '" + p
+					+ "' does not yet exist.");
+		return subjectToValueMap.get(s);
+	}
+
+	private final class InternalRow implements Row {
+		private final Node key;
+
+		InternalRow(final Node key) {
+			this.key = key;
+		}
+
+		@Override
+		public void setValue(Column column, Node value) {
+			if (value == null)
+				unSetX(key, column.getColumnKey());
+			else
+				setX(key, column.getColumnKey(), value);
+		}
+
+		@Override
+		public Node getValue(Column column) {
+			return getX(key, column.getColumnKey());
+		}
+		
+		@Override
+		public Node getValue(Node columnKey) {
+			return getX(key, columnKey);
+		}
+
+		@Override
+		public PropertyTable getTable() {
+			return PropertyTableHashMapImpl.this;
+		}
+
+		@Override
+		public Node getRowKey() {
+			return key;
+		}
+
+		@Override
+		public Collection<Column> getColumns() {
+			// TODO Auto-generated method stub
+			return PropertyTableHashMapImpl.this.getColumns();
+		}
+
+		@Override
+		public ExtendedIterator<Triple> getTripleIterator() {
+			ArrayList<Triple> triples = new ArrayList<Triple>();
+			for (Column column : getColumns()) {
+				Node value = this.getValue(column);
+				triples.add(Triple.create(key, column.getColumnKey(), value));
+			}
+			return WrappedIterator.create(triples.iterator());
+		}
+
+	}
+
+
+
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/517da327/src/main/java/com/hp/hpl/jena/propertytable/impl/PropertyTableImpl.java
----------------------------------------------------------------------
diff --git a/src/main/java/com/hp/hpl/jena/propertytable/impl/PropertyTableImpl.java b/src/main/java/com/hp/hpl/jena/propertytable/impl/PropertyTableImpl.java
deleted file mode 100644
index 1acb08f..0000000
--- a/src/main/java/com/hp/hpl/jena/propertytable/impl/PropertyTableImpl.java
+++ /dev/null
@@ -1,301 +0,0 @@
-/*
- * 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 java.util.Set;
-
-import org.apache.jena.atlas.iterator.Iter;
-import org.apache.jena.atlas.iterator.IteratorConcat;
-
-import com.google.common.collect.HashMultimap;
-import com.google.common.collect.SetMultimap;
-import com.hp.hpl.jena.graph.Node;
-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.util.iterator.ExtendedIterator;
-import com.hp.hpl.jena.util.iterator.WrappedIterator;
-
-/**
- * A PropertyTable Implementation using HashMap.
- * It contains PSO and POS indexes.
- * 
- */
-public class PropertyTableImpl implements PropertyTable {
-
-	private Map<Node, Column> columnIndex; // Maps property Node key to Column
-	private List<Column> columnList; // Stores the list of columns in the table
-	private Map<Node, Row> rowIndex; // Maps the subject Node key to Row.
-	private List<Row> rowList; // Stores the list of rows in the table
-
-	// PSO index
-	private Map<Node, Map<Node, Node>> valueIndex; // Maps column Node to
-													// (subject Node, value)
-													// pairs
-	// POS index
-	private Map<Node, SetMultimap<Node, Node>> valueReverseIndex; // Maps column
-																	// Node to
-																	// (value,
-																	// subject
-																	// Node)
-																	// pairs
-
-	PropertyTableImpl() {
-		columnIndex = new HashMap<Node, Column>();
-		columnList = new ArrayList<Column>();
-		rowIndex = new HashMap<Node, Row>();
-		rowList = new ArrayList<Row>();
-		valueIndex = new HashMap<Node, Map<Node, Node>>();
-		valueReverseIndex = new HashMap<Node, SetMultimap<Node, Node>>();
-	}
-
-	@Override
-	public ExtendedIterator<Triple> getTripleIterator() {
-		
-		// use PSO index to scan all the table (slow)
-		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) {
-		
-		// use PSO index directly (fast)
-		ArrayList<Triple> triples = new ArrayList<Triple>();
-		Map<Node, Node> values = valueIndex.get(column.getColumnKey());
-
-		for (Entry<Node, Node> entry : values.entrySet()) {
-			Node subject = entry.getKey();
-			Node value = entry.getValue();
-			triples.add(Triple.create(subject, column.getColumnKey(), value));
-		}
-		return WrappedIterator.create(triples.iterator());
-	}
-
-	@Override
-	public ExtendedIterator<Triple> getTripleIterator(Node value) {
-		
-		// use POS index ( O(n), n= column count )
-		IteratorConcat<Triple> iter = new IteratorConcat<Triple>();
-		for (Column column : this.getColumns()) {
-			ExtendedIterator<Triple> eIter = getTripleIterator(column);
-			iter.add(eIter);
-		}
-		return WrappedIterator.create(Iter.distinct(iter));
-	}
-
-	@Override
-	public ExtendedIterator<Triple> getTripleIterator(Column column, Node value) {
-		
-		// use POS index directly (fast)
-		Node p = column.getColumnKey();
-		final SetMultimap<Node, Node> valueToSubjectMap = valueReverseIndex
-				.get(p);
-		final Set<Node> subjects = valueToSubjectMap.get(value);
-		ArrayList<Triple> triples = new ArrayList<Triple>();
-		for (Node subject : subjects) {
-			triples.add(Triple.create(subject, p, value));
-		}
-		return WrappedIterator.create(triples.iterator());
-	}
-
-
-	@Override
-	public ExtendedIterator<Triple> getTripleIterator(Row row) {
-		// use PSO index ( O(n), n= column count )
-		ArrayList<Triple> triples = new ArrayList<Triple>();
-		for (Column column : getColumns()) {
-			Node value = row.getValue(column);
-			triples.add(Triple.create(row.getRowKey(), column.getColumnKey(), 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<Node, Node>());
-		valueReverseIndex.put(p, HashMultimap.<Node, Node> create());
-	}
-
-	@Override
-	public Row getRow(final Node s) {
-		if (s == null)
-			throw new NullPointerException("subject node is null");
-		Row row = rowIndex.get(s);
-		return row;
-
-	}
-	
-	@Override
-	public Row createRow(final Node s){
-		Row row = this.getRow(s);
-		if (row != null)
-			return row;
-
-		row = new InternalRow(s);
-		rowIndex.put(s, row);
-		rowList.add(row);
-
-		return row;
-	}
-	
-	@Override
-	public ExtendedIterator<Row> getRowIterator() {
-		return WrappedIterator.create(rowList.iterator());
-	}
-
-	private final void setX(final Node s, 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.");
-
-		Map<Node, Node> subjectToValueMap = valueIndex.get(p);
-		if (!columnIndex.containsKey(p) || subjectToValueMap == null)
-			throw new IllegalArgumentException("column: '" + p
-					+ "' does not yet exist.");
-
-		Node oldValue = subjectToValueMap.get(s);
-		subjectToValueMap.put(s, value);
-		addToReverseMap(p, s, oldValue, value);
-	}
-
-	private void addToReverseMap(final Node p, final Node s,
-			final Node oldValue, final Node value) {
-
-		final SetMultimap<Node, Node> valueToSubjectMap = valueReverseIndex
-				.get(p);
-		valueToSubjectMap.remove(oldValue, s);
-		valueToSubjectMap.put(value, s);
-	}
-
-	private void unSetX(final Node s, final Node p) {
-
-		final Map<Node, Node> subjectToValueMap = valueIndex.get(p);
-		if (!columnIndex.containsKey(p) || subjectToValueMap == null)
-			throw new IllegalArgumentException("column: '" + p
-					+ "' does not yet exist.");
-
-		final Node value = subjectToValueMap.get(s);
-		if (value == null)
-			return;
-
-		subjectToValueMap.remove(s);
-		removeFromReverseMap(p, s, value);
-	}
-
-	private void removeFromReverseMap(final Node p, final Node s,
-			final Node value) {
-		final SetMultimap<Node, Node> valueTokeysMap = valueReverseIndex.get(p);
-		valueTokeysMap.remove(s, value);
-	}
-
-	private Node getX(final Node s, final Node p) {
-		final Map<Node, Node> subjectToValueMap = valueIndex.get(p);
-		if (!columnIndex.containsKey(p) || subjectToValueMap == null)
-			throw new IllegalArgumentException("column: '" + p
-					+ "' does not yet exist.");
-		return subjectToValueMap.get(s);
-	}
-
-	private final class InternalRow implements Row {
-		private final Node key;
-
-		InternalRow(final Node key) {
-			this.key = key;
-		}
-
-		@Override
-		public void setValue(Column column, Node value) {
-			if (value == null)
-				unSetX(key, column.getColumnKey());
-			else
-				setX(key, column.getColumnKey(), value);
-		}
-
-		@Override
-		public Node getValue(Column column) {
-			return getX(key, column.getColumnKey());
-		}
-		
-		@Override
-		public Node getValue(Node columnKey) {
-			return getX(key, columnKey);
-		}
-
-		@Override
-		public PropertyTable getTable() {
-			return PropertyTableImpl.this;
-		}
-
-		@Override
-		public Node getRowKey() {
-			return key;
-		}
-
-		@Override
-		public Collection<Column> getColumns() {
-			// TODO Auto-generated method stub
-			return PropertyTableImpl.this.getColumns();
-		}
-
-		@Override
-		public ExtendedIterator<Triple> getTripleIterator() {
-			ArrayList<Triple> triples = new ArrayList<Triple>();
-			for (Column column : getColumns()) {
-				Node value = this.getValue(column);
-				triples.add(Triple.create(key, column.getColumnKey(), value));
-			}
-			return WrappedIterator.create(triples.iterator());
-		}
-
-	}
-
-
-
-}

http://git-wip-us.apache.org/repos/asf/jena/blob/517da327/src/test/java/com/hp/hpl/jena/propertytable/impl/GraphCSVTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/com/hp/hpl/jena/propertytable/impl/GraphCSVTest.java b/src/test/java/com/hp/hpl/jena/propertytable/impl/GraphCSVTest.java
index d85c128..3145a19 100644
--- a/src/test/java/com/hp/hpl/jena/propertytable/impl/GraphCSVTest.java
+++ b/src/test/java/com/hp/hpl/jena/propertytable/impl/GraphCSVTest.java
@@ -34,10 +34,10 @@ import com.hp.hpl.jena.sparql.algebra.Algebra;
 import com.hp.hpl.jena.sparql.algebra.Op;
 import com.hp.hpl.jena.sparql.engine.main.StageBuilder;
 import com.hp.hpl.jena.sparql.engine.main.StageGenerator;
+import com.hp.hpl.jena.util.PrintUtil;
 
 public class GraphCSVTest extends Assert {
 	
-	@Ignore
 	@Test
 	public void testGraphCSV() throws Exception {
 		String file = "src/test/resources/test.csv";


Mime
View raw message