http://git-wip-us.apache.org/repos/asf/jena/blob/e7ac8b4d/jena-csv/src/test/resources/HEFCE_organogram_senior_data_31032011.csv ---------------------------------------------------------------------- diff --git a/jena-csv/src/test/resources/HEFCE_organogram_senior_data_31032011.csv b/jena-csv/src/test/resources/HEFCE_organogram_senior_data_31032011.csv new file mode 100644 index 0000000..77df38f --- /dev/null +++ b/jena-csv/src/test/resources/HEFCE_organogram_senior_data_31032011.csv @@ -0,0 +1,5 @@ +Post Unique Reference,Name,Grade,Job Title,Job/Team Function,Parent Department,Organisation,Unit,Contact Phone,Contact E-mail,Reports to Senior Post,Salary Cost of Reports (£),FTE,Actual Pay Floor (£),Actual Pay Ceiling (£),,Profession,Notes,Valid? +90115,Steve Egan,SCS1A,Deputy Chief Executive,Finance and Corporate Resources,Department for Business Innovation and Skills,Higher Education Funding Council for England,Finance and Corporate Resources,0117 931 7408,[email protected],90334,5883433,1,120000,124999,,Finance,,1 +90250,David Sweeney,SCS1A,Director,"Research, Innovation and Skills",Department for Business Innovation and Skills,Higher Education Funding Council for England,"Research, Innovation and Skills",0117 931 7304,[email protected],90334,1207171,1,110000,114999,,Policy,,1 +90284,Heather Fry,SCS1A,Director,Education and Participation,Department for Business Innovation and Skills,Higher Education Funding Council for England,Education and Participation,0117 931 7280,[email protected],90334,1645195,1,100000,104999,,Policy,,1 +90334,Sir Alan Langlands,SCS4,Chief Executive,Chief Executive,Department for Business Innovation and Skills,Higher Education Funding Council for England,HEFCE,0117 931 7300/7341,[email protected],xx,0,1,230000,234999,,Policy,,1
http://git-wip-us.apache.org/repos/asf/jena/blob/e7ac8b4d/jena-csv/src/test/resources/PLOSone-search-results.csv ---------------------------------------------------------------------- diff --git a/jena-csv/src/test/resources/PLOSone-search-results.csv b/jena-csv/src/test/resources/PLOSone-search-results.csv new file mode 100644 index 0000000..ab6ae2c --- /dev/null +++ b/jena-csv/src/test/resources/PLOSone-search-results.csv @@ -0,0 +1,6 @@ +id,doi,publication_date,title_display,author +10.1371/journal.pone.0095131,10.1371/journal.pone.0095131,2014-06-05T00:00:00Z,"Genotyping of French <i>Bacillus anthracis</i> Strains Based on 31-Loci Multi Locus VNTR Analysis: Epidemiology, Marker Evaluation, and Update of the Internet Genotype Database","Simon Thierry,Christophe Tourterel,Philippe Le Flèche,Sylviane Derzelle,Neira Dekhil,Christiane Mendy,Cécile Colaneri,Gilles Vergnaud,Nora Madani" +10.1371/journal.pone.0095156,10.1371/journal.pone.0095156,2014-06-05T00:00:00Z,Pathways Mediating the Interaction between Endothelial Progenitor Cells (EPCs) and Platelets,"Oshrat Raz,Dorit L Lev,Alexander Battler,Eli I Lev" +10.1371/journal.pone.0095275,10.1371/journal.pone.0095275,2014-06-05T00:00:00Z,Identification of Divergent Protein Domains by Combining HMM-HMM Comparisons and Co-Occurrence Detection,"Amel Ghouila,Isabelle Florent,Fatma Zahra Guerfali,Nicolas Terrapon,Dhafer Laouini,Sadok Ben Yahia,Olivier Gascuel,Laurent Bréhélin" +10.1371/journal.pone.0096098,10.1371/journal.pone.0096098,2014-06-05T00:00:00Z,Baseline CD4 Cell Counts of Newly Diagnosed HIV Cases in China: 2006â2012,"Houlin Tang,Yurong Mao,Cynthia X Shi,Jing Han,Liyan Wang,Juan Xu,Qianqian Qin,Roger Detels,Zunyou Wu" +10.1371/journal.pone.0097475,10.1371/journal.pone.0097475,2014-06-05T00:00:00Z,Crystal Structure of the Open State of the <i>Neisseria gonorrhoeae</i> MtrE Outer Membrane Channel,"Hsiang-Ting Lei,Tsung-Han Chou,Chih-Chia Su,Jani Reddy Bolla,Nitin Kumar,Abhijith Radhakrishnan,Feng Long,Jared A Delmar,Sylvia V Do,Kanagalaghatta R Rajashankar,William M Shafer,Edward W Yu" \ No newline at end of file http://git-wip-us.apache.org/repos/asf/jena/blob/e7ac8b4d/jena-csv/src/test/resources/Palo_Alto_Trees.csv ---------------------------------------------------------------------- diff --git a/jena-csv/src/test/resources/Palo_Alto_Trees.csv b/jena-csv/src/test/resources/Palo_Alto_Trees.csv new file mode 100644 index 0000000..c534c47 --- /dev/null +++ b/jena-csv/src/test/resources/Palo_Alto_Trees.csv @@ -0,0 +1,6 @@ +GID,Private,Tree ID,Admin Area,Side of Street,On Street,From Street,To Street,Street_Name,Situs Number,Address Estimated,Lot Side,Serial Number,Tree Site,Species,Trim Cycle,Diameter at Breast Ht,Trunk Count,Height Code,Canopy Width,Trunk Condition,Structure Condition,Crown Condition,Pest Condition,Condition Calced,Condition Rating,Vigor,Cable Presence,Stake Presence,Grow Space,Utility Presence,Distance from Property,Inventory Date,Staff Name,Comments,Zip,City Name,Longitude,Latitude,Protected,Designated,Heritage,Appraised Value,Hardscape,Identifier,Location Feature ID,Install Date,Feature Name,KML,FusionMarkerIcon +1,True,29,,,ADDISON AV,EMERSON ST,RAMONA ST,ADDISON AV,203,,Front,,2,Celtis australis,Large Tree Routine Prune,11,1,25-30,15-30,,Good,5,,,Good,2,False,False,Planting Strip,,44,10/18/2010,BK,,,Palo Alto,-122.1565172,37.4409561,False,False,False,,None,40,13872,,"Tree: 29 site 2 at 203 ADDISON AV, on ADDISON AV 44 from pl","<Point><coordinates>-122.156485,37.440963</coordinates></Point>",small_green +2,True,30,,,EMERSON ST,CHANNING AV,ADDISON AV,ADDISON AV,203,,Left,,1,Liquidambar styraciflua,Large Tree Routine Prune,11,1,50-55,15-30,Good,Good,5,,,Good,2,False,False,Planting Strip,,21,6/2/2010,BK,,,Palo Alto,-122.1567812,37.440951,False,False,False,,None,41,13872,,"Tree: 30 site 1 at 203 ADDISON AV, on EMERSON ST 21 from pl","<Point><coordinates>-122.156749,37.440958</coordinates></Point>",small_green +3,True,31,,,EMERSON ST,CHANNING AV,ADDISON AV,ADDISON AV,203,,Left,,2,Liquidambar styraciflua,Large Tree Routine Prune,11,1,40-45,15-30,Good,Good,5,,,Good,2,False,False,Planting Strip,,54,6/2/2010,BK,,,Palo Alto,-122.1566921,37.4408948,False,False,False,,Low,42,13872,,"Tree: 31 site 2 at 203 ADDISON AV, on EMERSON ST 54 from pl","<Point><coordinates>-122.156659,37.440902</coordinates></Point>",small_green +4,True,32,,,ADDISON AV,EMERSON ST,RAMONA ST,ADDISON AV,209,,Front,,1,Ulmus parvifolia,Large Tree Routine Prune,18,1,35-40,30-45,Good,Good,5,,,Good,2,False,False,Planting Strip,,21,6/2/2010,BK,,,Palo Alto,-122.1564595,37.4410143,False,False,False,,Medium,43,13873,,"Tree: 32 site 1 at 209 ADDISON AV, on ADDISON AV 21 from pl","<Point><coordinates>-122.156427,37.441022</coordinates></Point>",small_green +5,True,33,,,ADDISON AV,EMERSON ST,RAMONA ST,ADDISON AV,219,,Front,,1,Eriobotrya japonica,Large Tree Routine Prune,7,1,15-20,0-15,Good,Good,3,,,Good,1,False,False,Planting Strip,,16,6/1/2010,BK,,,Palo Alto,-122.1563676,37.441107,False,False,False,,None,44,13874,,"Tree: 33 site 1 at 219 ADDISON AV, on ADDISON AV 16 from pl","<Point><coordinates>-122.156335,37.441114</coordinates></Point>",small_green http://git-wip-us.apache.org/repos/asf/jena/blob/e7ac8b4d/jena-csv/src/test/resources/log4j.properties ---------------------------------------------------------------------- diff --git a/jena-csv/src/test/resources/log4j.properties b/jena-csv/src/test/resources/log4j.properties new file mode 100644 index 0000000..6d3889d --- /dev/null +++ b/jena-csv/src/test/resources/log4j.properties @@ -0,0 +1,19 @@ +log4j.rootLogger=INFO, stdlog + +log4j.appender.stdlog=org.apache.log4j.ConsoleAppender +## log4j.appender.stdlog.target=System.err +log4j.appender.stdlog.layout=org.apache.log4j.PatternLayout +log4j.appender.stdlog.layout.ConversionPattern=%d{HH:mm:ss} %-5p %-25c{1} :: %m%n + +# Execution logging +log4j.logger.com.hp.hpl.jena.arq.info=INFO +log4j.logger.com.hp.hpl.jena.arq.exec=INFO + +# Everything else in Jena +log4j.logger.com.hp.hpl.jena=WARN +log4j.logger.org.openjena=WARN +log4j.logger.org.openjena.riot=INFO + +# Apache Commons HTTP +# May be useful to turn up to DEBUG if debugging HTTP communication issues +log4j.logger.org.apache.http=WARN http://git-wip-us.apache.org/repos/asf/jena/blob/e7ac8b4d/jena-csv/src/test/resources/test.csv ---------------------------------------------------------------------- diff --git a/jena-csv/src/test/resources/test.csv b/jena-csv/src/test/resources/test.csv new file mode 100644 index 0000000..b9ac0e1 --- /dev/null +++ b/jena-csv/src/test/resources/test.csv @@ -0,0 +1,3 @@ +Town,Population,Predicate With Space,`~!@#$%^&*()-_=+[{]}|\;:'"<.>/?,1234 +Southton,123000.0,PredicateWithSpace1,NonURICharacters1,DigitalLocalName1 +Northville,654000,PredicateWithSpace2,NonURICharacters2,DigitalLocalName2 http://git-wip-us.apache.org/repos/asf/jena/blob/e7ac8b4d/pom.xml ---------------------------------------------------------------------- diff --git a/pom.xml b/pom.xml deleted file mode 100644 index 2ba7acc..0000000 --- a/pom.xml +++ /dev/null @@ -1,189 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<!-- - 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. ---> - -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> - <modelVersion>4.0.0</modelVersion> - <groupId>org.apache.jena</groupId> - <artifactId>jena-csv</artifactId> - <packaging>jar</packaging> - <name>Apache Jena - Data Tables for RDF and SPARQL</name> - <version>1.0.1-SNAPSHOT</version> - - <parent> - <groupId>org.apache.jena</groupId> - <artifactId>jena-parent</artifactId> - <version>10</version> - <relativePath /> - </parent> - - - <!-- Need if the parent is a snapshot --> - <repositories> - <repository> - <id>apache.snapshots</id> - <name>Apache Snapshot Repository</name> - <url>http://repository.apache.org/snapshots</url> - <releases> - <enabled>false</enabled> - </releases> - </repository> - </repositories> - - <description>jena-csv is for getting CSVs into a form that is amenable to Jena SPARQL processing, and doing so in a way that is not specific to CSV files. It includes getting the right architecture in place for regular table shaped data, using the core abstraction of PropertyTable.</description> - - <scm> - <connection>scm:svn:https://svn.apache.org/repos/asf/jena/Experimental/jena-csv</connection> - <developerConnection>scm:svn:https://svn.apache.org/repos/asf/jena/Experimental/jena-csv</developerConnection> - <url>https://svn.apache.org/repos/asf/jena/Experimental/jena-csv</url> - </scm> - - <properties> - <maven.build.timestamp.format>yyyy-MM-dd'T'HH:mm:ssZ</maven.build.timestamp.format> - <build.time.xsd>${maven.build.timestamp}</build.time.xsd> - </properties> - - <dependencies> - - <!-- All Jena libs --> - <dependency> - <groupId>org.apache.jena</groupId> - <artifactId>apache-jena-libs</artifactId> - <version>2.12.0</version> - <type>pom</type> - </dependency> - - <!-- Google Code Guava --> - <dependency> - <groupId>com.google.guava</groupId> - <artifactId>guava</artifactId> - <version>17.0</version> - </dependency> - - <!-- Testing support --> - <dependency> - <groupId>org.apache.jena</groupId> - <artifactId>jena-arq</artifactId> - <version>2.12.0</version> - <type>jar</type> - <classifier>tests</classifier> - <scope>test</scope> - </dependency> - - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <scope>test</scope> - </dependency> - </dependencies> - - - - <build> - <plugins> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-compiler-plugin</artifactId> - </plugin> - - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-surefire-plugin</artifactId> - <configuration> - <systemPropertyVariables> - <log4j.configuration>file:src/test/resources/log4j.properties</log4j.configuration> - </systemPropertyVariables> - - <includes> - <include>**/TS_*.java</include> - </includes> - </configuration> - </plugin> - - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-jar-plugin</artifactId> - </plugin> - - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-source-plugin</artifactId> - <executions> - <execution> - <id>attach-sources</id> - <goals> - <goal>jar-no-fork</goal> - </goals> - </execution> - <!-- Only material in the main jar <execution> <id>attach-sources-test</id> - <goals> <goal>test-jar-no-fork</goal> </goals> </execution> --> - </executions> - </plugin> - - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-javadoc-plugin</artifactId> - <configuration> - <version>true</version> - <show>public</show> - <quiet>true</quiet> - <encoding>UTF-8</encoding> - <windowtitle>${project.name} ${project.version}</windowtitle> - <doctitle>${project.name} ${project.version}</doctitle> - <bottom>Licenced under the Apache License, Version 2.0</bottom> - </configuration> - </plugin> - - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-resources-plugin</artifactId> - <configuration> - <encoding>UTF-8</encoding> - </configuration> - </plugin> - - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-dependency-plugin</artifactId> - <configuration> - <overWriteReleases>false</overWriteReleases> - <overWriteIfNewer>true</overWriteIfNewer> - </configuration> - </plugin> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-eclipse-plugin</artifactId> - <configuration> - <!-- By default, have separate Eclipse and maven build areas --> - <buildOutputDirectory>${project.build.directory}/classes</buildOutputDirectory> - <downloadSources>true</downloadSources> - <downloadJavadocs>false</downloadJavadocs> - </configuration> - </plugin> - - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-release-plugin</artifactId> - <configuration> - <tagBase>https://svn.apache.org/repos/asf/jena/tags/</tagBase> - </configuration> - </plugin> - </plugins> - - </build> - -</project> http://git-wip-us.apache.org/repos/asf/jena/blob/e7ac8b4d/src/main/java/org/apache/jena/propertytable/Column.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/jena/propertytable/Column.java b/src/main/java/org/apache/jena/propertytable/Column.java deleted file mode 100644 index 2e6b6b2..0000000 --- a/src/main/java/org/apache/jena/propertytable/Column.java +++ /dev/null @@ -1,45 +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 org.apache.jena.propertytable; - -import java.util.List; - -import com.hp.hpl.jena.graph.Node; - -/** - * Each Column of the PropertyTable has an unique columnKey Node of the predicate (or p for short). - * - */ -public interface Column { - - /** - * @return the PropertyTable it belongs to - */ - PropertyTable getTable(); - - /** - * @return the columnKey Node of the predicate - */ - Node getColumnKey(); - - /** - * @return all the values within a Column - */ - List<Node> getValues(); - -} http://git-wip-us.apache.org/repos/asf/jena/blob/e7ac8b4d/src/main/java/org/apache/jena/propertytable/PropertyTable.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/jena/propertytable/PropertyTable.java b/src/main/java/org/apache/jena/propertytable/PropertyTable.java deleted file mode 100644 index 6c9b9a8..0000000 --- a/src/main/java/org/apache/jena/propertytable/PropertyTable.java +++ /dev/null @@ -1,126 +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 org.apache.jena.propertytable; - -import java.util.Collection; -import java.util.List; - -import com.hp.hpl.jena.graph.Node; -import com.hp.hpl.jena.graph.Triple; -import com.hp.hpl.jena.util.iterator.ExtendedIterator; - -/** - * PropertyTable is designed to be a table of RDF terms, or Nodes in Jena. - * Each Column of the PropertyTable has an unique columnKey Node of the predicate (or p for short). - * Each Row of the PropertyTable has an unique rowKey Node of the subject (or s for short). - * You can use getColumn() to get the Column by its columnKey Node of the predicate, while getRow() for Row. - * - */ -public interface PropertyTable { - - /** - * Query for ?s <p> <o> - * @param column the Column with the columnKey Node of the predicate - * @param value the object (or value) Node - * @return the ExtendedIterator of the matching Triples - */ - ExtendedIterator<Triple> getTripleIterator(Column column, Node value); - - /** - * Query for ?s <p> ?o - * @param column the Column with the columnKey Node of the predicate - * @return the ExtendedIterator of the matching Triples - */ - ExtendedIterator<Triple> getTripleIterator(Column column); - - /** - * Query for ?s ?p <o> - * @param value the object (or value) Node - * @return the ExtendedIterator of the matching Triples - */ - ExtendedIterator<Triple> getTripleIterator(Node value); - - /** - * Query for <s> ?p ?o - * @param row the Row with the rowKey Node of the subject - * @return the ExtendedIterator of the matching Triples - */ - ExtendedIterator<Triple> getTripleIterator(Row row); - - /** - * Query for ?s ?p ?o - * @return all of the Triples of the PropertyTable - */ - ExtendedIterator<Triple> getTripleIterator(); - - /** - * @return all of the Columns of the PropertyTable - */ - Collection<Column> getColumns(); - - /** - * Get Column by its columnKey Node of the predicate - * @param p columnKey Node of the predicate - * @return the Column - */ - Column getColumn(Node p); - - /** - * Create a Column by its columnKey Node of the predicate - * @param p - */ - Column createColumn(Node p); - - /** - * Get Row by its rowKey Node of the subject - * @param s rowKey Node of the subject - * @return the Row - */ - Row getRow(Node s); - - - /** - * Create Row by its rowKey Node of the subject - * @param s rowKey Node of the subject - * @return the Row created - */ - Row createRow(Node s); - - - /** - * Get all of the rows - */ - List<Row> getAllRows() ; - - - /** - * Get all the values within a Column - * @param column - * @return the values - */ - List<Node> getColumnValues(Column column); - - /** - * Get the Rows matching the value of a Column - * @param column the Column with the columnKey Node of the predicate - * @param value the object (or value) Node - * @return the matching Rows - */ - Collection<Row> getMatchingRows(Column column, Node value); - -} http://git-wip-us.apache.org/repos/asf/jena/blob/e7ac8b4d/src/main/java/org/apache/jena/propertytable/Row.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/jena/propertytable/Row.java b/src/main/java/org/apache/jena/propertytable/Row.java deleted file mode 100644 index bc6d068..0000000 --- a/src/main/java/org/apache/jena/propertytable/Row.java +++ /dev/null @@ -1,75 +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 org.apache.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; - -/** - * Each Row of the PropertyTable has an unique rowKey Node of the subject (or s for short). - * - */ -public interface Row { - - /** - * @return the PropertyTable it belongs to - */ - PropertyTable getTable(); - - /** - * Set the value of the Column in this Row - * @param column - * @param value - */ - void setValue(Column column, Node value); - - /** - * Get the value of the Column in this Row - * @param column - * @return value - */ - Node getValue(Column column); - - - /** - * Get the value of the Column in this Row - * @param ColumnKey - * @return value - */ - Node getValue(Node ColumnKey); - - /** - * @return the rowKey Node of the subject - */ - Node getRowKey(); - - /** - * @return the Triple Iterator over the values in this Row - */ - ExtendedIterator<Triple> getTripleIterator(); - - /** - * @return all of the Columns of the PropertyTable - */ - Collection<Column> getColumns(); - -} http://git-wip-us.apache.org/repos/asf/jena/blob/e7ac8b4d/src/main/java/org/apache/jena/propertytable/graph/GraphCSV.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/jena/propertytable/graph/GraphCSV.java b/src/main/java/org/apache/jena/propertytable/graph/GraphCSV.java deleted file mode 100644 index d002ec6..0000000 --- a/src/main/java/org/apache/jena/propertytable/graph/GraphCSV.java +++ /dev/null @@ -1,62 +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 org.apache.jena.propertytable.graph; - -import org.apache.jena.propertytable.PropertyTable; -import org.apache.jena.propertytable.impl.PropertyTableBuilder; - - -/** - * GraphCSV is a sub class of GraphPropertyTable aiming at CSV data. - * Its constructor takes a CSV file path as the parameter, parse the file using a CSV Parser, - * and makes a PropertyTable through PropertyTableBuilder. - * - */ -public class GraphCSV extends GraphPropertyTable { - - 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); - } - - // use the Java array implementation of PropertyTable for default - 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/e7ac8b4d/src/main/java/org/apache/jena/propertytable/graph/GraphPropertyTable.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/jena/propertytable/graph/GraphPropertyTable.java b/src/main/java/org/apache/jena/propertytable/graph/GraphPropertyTable.java deleted file mode 100644 index 3f1e930..0000000 --- a/src/main/java/org/apache/jena/propertytable/graph/GraphPropertyTable.java +++ /dev/null @@ -1,203 +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 org.apache.jena.propertytable.graph; - -import java.util.ArrayList; -import java.util.Locale; - -import org.apache.jena.propertytable.Column; -import org.apache.jena.propertytable.PropertyTable; -import org.apache.jena.propertytable.Row; - - -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.sparql.core.BasicPattern; -import com.hp.hpl.jena.util.iterator.ExtendedIterator; -import com.hp.hpl.jena.util.iterator.Filter; -import com.hp.hpl.jena.util.iterator.NullIterator; -import com.hp.hpl.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(TripleMatch m) { - //System.out.println(m); - - if (this.pt == null) { - return NullIterator.instance(); - } - - ExtendedIterator<Triple> iter = null; - - Node s = m.getMatchSubject(); - Node p = m.getMatchPredicate(); - Node o = m.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(m.asTriple())); - - } - - 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 extends Filter<Row> { - final protected RowMatch rMatch; - - public RowMatchFilterEquality(RowMatch rMatch) { - this.rMatch = rMatch; - } - - @Override - public boolean accept(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 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; - } - - private boolean isConcrete(Node node) { - boolean wild = (node == null || node == Node.ANY); - return !wild; - } - -} http://git-wip-us.apache.org/repos/asf/jena/blob/e7ac8b4d/src/main/java/org/apache/jena/propertytable/graph/QueryIterPropertyTable.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/jena/propertytable/graph/QueryIterPropertyTable.java b/src/main/java/org/apache/jena/propertytable/graph/QueryIterPropertyTable.java deleted file mode 100644 index 9b13e6c..0000000 --- a/src/main/java/org/apache/jena/propertytable/graph/QueryIterPropertyTable.java +++ /dev/null @@ -1,115 +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 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 com.hp.hpl.jena.graph.Graph; -import com.hp.hpl.jena.graph.Node; -import com.hp.hpl.jena.graph.Triple; -import com.hp.hpl.jena.sparql.core.BasicPattern; -import com.hp.hpl.jena.sparql.engine.ExecutionContext; -import com.hp.hpl.jena.sparql.engine.QueryIterator; -import com.hp.hpl.jena.sparql.engine.binding.Binding; -import com.hp.hpl.jena.sparql.engine.iterator.QueryIter1; -import com.hp.hpl.jena.sparql.serializer.SerializationContext; -import com.hp.hpl.jena.sparql.util.FmtUtils; -import com.hp.hpl.jena.sparql.util.Utils; - -/** - * 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(Utils.className(this)); - out.println(); - out.incIndent(); - FmtUtils.formatPattern(out, pattern, sCxt); - out.decIndent(); - } -} http://git-wip-us.apache.org/repos/asf/jena/blob/e7ac8b4d/src/main/java/org/apache/jena/propertytable/graph/QueryIterPropertyTableRow.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/jena/propertytable/graph/QueryIterPropertyTableRow.java b/src/main/java/org/apache/jena/propertytable/graph/QueryIterPropertyTableRow.java deleted file mode 100644 index a479e25..0000000 --- a/src/main/java/org/apache/jena/propertytable/graph/QueryIterPropertyTableRow.java +++ /dev/null @@ -1,243 +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 org.apache.jena.propertytable.graph; - -import java.util.ArrayList; -import java.util.List; - -import org.apache.jena.propertytable.PropertyTable; -import org.apache.jena.propertytable.Row; - - -import com.hp.hpl.jena.graph.Node; -import com.hp.hpl.jena.graph.Triple; -import com.hp.hpl.jena.sparql.ARQInternalErrorException; -import com.hp.hpl.jena.sparql.core.BasicPattern; -import com.hp.hpl.jena.sparql.core.Var; -import com.hp.hpl.jena.sparql.engine.ExecutionContext; -import com.hp.hpl.jena.sparql.engine.QueryIterator; -import com.hp.hpl.jena.sparql.engine.binding.Binding; -import com.hp.hpl.jena.sparql.engine.binding.BindingFactory; -import com.hp.hpl.jena.sparql.engine.binding.BindingMap; -import com.hp.hpl.jena.sparql.engine.iterator.QueryIter; -import com.hp.hpl.jena.sparql.engine.iterator.QueryIterRepeatApply; -import com.hp.hpl.jena.util.iterator.ClosableIterator; -import com.hp.hpl.jena.util.iterator.ExtendedIterator; -import com.hp.hpl.jena.util.iterator.NiceIterator; -import com.hp.hpl.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/e7ac8b4d/src/main/java/org/apache/jena/propertytable/graph/RowMatch.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/jena/propertytable/graph/RowMatch.java b/src/main/java/org/apache/jena/propertytable/graph/RowMatch.java deleted file mode 100644 index 15fe088..0000000 --- a/src/main/java/org/apache/jena/propertytable/graph/RowMatch.java +++ /dev/null @@ -1,48 +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 org.apache.jena.propertytable.graph; - -import com.hp.hpl.jena.graph.Node; -import com.hp.hpl.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/e7ac8b4d/src/main/java/org/apache/jena/propertytable/graph/StageGeneratorPropertyTable.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/jena/propertytable/graph/StageGeneratorPropertyTable.java b/src/main/java/org/apache/jena/propertytable/graph/StageGeneratorPropertyTable.java deleted file mode 100644 index 9c3457b..0000000 --- a/src/main/java/org/apache/jena/propertytable/graph/StageGeneratorPropertyTable.java +++ /dev/null @@ -1,57 +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 org.apache.jena.propertytable.graph; - - -import com.hp.hpl.jena.graph.Graph; -import com.hp.hpl.jena.sparql.core.BasicPattern; -import com.hp.hpl.jena.sparql.engine.ExecutionContext; -import com.hp.hpl.jena.sparql.engine.QueryIterator; -import com.hp.hpl.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/e7ac8b4d/src/main/java/org/apache/jena/propertytable/impl/ColumnImpl.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/jena/propertytable/impl/ColumnImpl.java b/src/main/java/org/apache/jena/propertytable/impl/ColumnImpl.java deleted file mode 100644 index f846aee..0000000 --- a/src/main/java/org/apache/jena/propertytable/impl/ColumnImpl.java +++ /dev/null @@ -1,58 +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 org.apache.jena.propertytable.impl; - - -import java.util.List; - -import org.apache.jena.propertytable.Column; -import org.apache.jena.propertytable.PropertyTable; - -import com.hp.hpl.jena.graph.Node; - -/** - * 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/e7ac8b4d/src/main/java/org/apache/jena/propertytable/impl/PropertyTableArrayImpl.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/jena/propertytable/impl/PropertyTableArrayImpl.java b/src/main/java/org/apache/jena/propertytable/impl/PropertyTableArrayImpl.java deleted file mode 100644 index b8e2708..0000000 --- a/src/main/java/org/apache/jena/propertytable/impl/PropertyTableArrayImpl.java +++ /dev/null @@ -1,346 +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 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.propertytable.Column; -import org.apache.jena.propertytable.PropertyTable; -import org.apache.jena.propertytable.Row; - -import com.hp.hpl.jena.graph.Node; -import com.hp.hpl.jena.graph.Triple; -import com.hp.hpl.jena.util.iterator.ExtendedIterator; -import com.hp.hpl.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/e7ac8b4d/src/main/java/org/apache/jena/propertytable/impl/PropertyTableBuilder.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/jena/propertytable/impl/PropertyTableBuilder.java b/src/main/java/org/apache/jena/propertytable/impl/PropertyTableBuilder.java deleted file mode 100644 index 665c282..0000000 --- a/src/main/java/org/apache/jena/propertytable/impl/PropertyTableBuilder.java +++ /dev/null @@ -1,134 +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 org.apache.jena.propertytable.impl; - -import java.io.InputStream; -import java.util.ArrayList; -import java.util.List; - -import org.apache.jena.atlas.csv.CSVParser; -import org.apache.jena.atlas.csv.CSVTokenIterator; -import org.apache.jena.atlas.io.IO; -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; - -import com.hp.hpl.jena.datatypes.xsd.XSDDatatype; -import com.hp.hpl.jena.graph.Node; -import com.hp.hpl.jena.graph.NodeFactory; - - -/** - * 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) ; - CSVTokenIterator iterator = new CSVTokenIterator(input) ; - return fillPropertyTable(table, iterator, csvFilePath); - } - - protected static PropertyTable fillPropertyTable(PropertyTable table, CSVTokenIterator iterator, String csvFilePath){ - if (table == null){ - return null; - } - CSVParser parser = new CSVParser (iterator); - 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) { - String uri = createColumnKeyURI(csvFilePath, column); - Node p = NodeFactory.createURI(uri); - predicates.add(p); - table.createColumn(p); - } - } else { - 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; - } -} http://git-wip-us.apache.org/repos/asf/jena/blob/e7ac8b4d/src/main/java/org/apache/jena/propertytable/impl/PropertyTableHashMapImpl.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/jena/propertytable/impl/PropertyTableHashMapImpl.java b/src/main/java/org/apache/jena/propertytable/impl/PropertyTableHashMapImpl.java deleted file mode 100644 index b74925b..0000000 --- a/src/main/java/org/apache/jena/propertytable/impl/PropertyTableHashMapImpl.java +++ /dev/null @@ -1,357 +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 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 java.util.Map.Entry; -import java.util.Set; - -import org.apache.jena.atlas.iterator.Iter; -import org.apache.jena.atlas.iterator.IteratorConcat; -import org.apache.jena.propertytable.Column; -import org.apache.jena.propertytable.PropertyTable; -import org.apache.jena.propertytable.Row; - -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.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 Column 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()); - return getColumn(p); - } - - @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 List<Row> getAllRows() { - return rowList; - } - - - - @Override - public List<Node> getColumnValues(Column column) { - if (column == null || column.getColumnKey() == null) - throw new NullPointerException("column is null"); - - Map<Node, Node> values = valueIndex.get(column.getColumnKey()); - - List<Node> list = new ArrayList<Node>(values.size()); - list.addAll(values.values()); - 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"); - - - Node p = column.getColumnKey(); - final SetMultimap<Node, Node> valueToSubjectMap = valueReverseIndex - .get(p); - final Set<Node> subjects = valueToSubjectMap.get(value); - - final ArrayList<Row> matchingRows = new ArrayList<Row>(); - for (Node subject : subjects) { - matchingRows.add(this.getRow(subject)); - } - return matchingRows; - } - - 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/e7ac8b4d/src/main/java/org/apache/jena/propertytable/lang/LangCSV.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/jena/propertytable/lang/LangCSV.java b/src/main/java/org/apache/jena/propertytable/lang/LangCSV.java deleted file mode 100644 index ccda47e..0000000 --- a/src/main/java/org/apache/jena/propertytable/lang/LangCSV.java +++ /dev/null @@ -1,229 +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 org.apache.jena.propertytable.lang; - -import static org.apache.jena.riot.RDFLanguages.CSV; - -import java.io.InputStream; -import java.io.Reader; -import java.util.ArrayList; -import java.util.List; - -import org.apache.jena.atlas.csv.CSVParser; -import org.apache.jena.atlas.web.ContentType; -import org.apache.jena.propertytable.util.IRILib; -import org.apache.jena.riot.Lang; -import org.apache.jena.riot.RDFLanguages; -import org.apache.jena.riot.RDFParserRegistry; -import org.apache.jena.riot.ReaderRIOT; -import org.apache.jena.riot.ReaderRIOTFactory; -import org.apache.jena.riot.lang.LangRIOT; -import org.apache.jena.riot.system.ErrorHandler; -import org.apache.jena.riot.system.ErrorHandlerFactory; -import org.apache.jena.riot.system.IRIResolver; -import org.apache.jena.riot.system.ParserProfile; -import org.apache.jena.riot.system.RiotLib; -import org.apache.jena.riot.system.StreamRDF; - -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.sparql.util.Context; - -/** - * The LangRIOT implementation for CSV - * - */ -public class LangCSV implements LangRIOT { - - public static final String CSV_PREFIX = "http://w3c/future-csv-vocab/"; - public static final String CSV_ROW = CSV_PREFIX + "row"; - - private InputStream input = null; - private Reader reader = null; - private String base; - private String filename; - private StreamRDF sink; - private ParserProfile profile; // Warning - we don't use all of this. - - public static void register(){ - RDFParserRegistry.removeRegistration(Lang.CSV); - RDFParserRegistry.registerLangTriples(Lang.CSV, new ReaderRIOTFactoryCSV()); - } - - @Override - public Lang getLang() { - return RDFLanguages.CSV; - } - - @Override - public ParserProfile getProfile() { - return profile; - } - - @Override - public void setProfile(ParserProfile profile) { - this.profile = profile; - } - - public LangCSV(Reader reader, String base, String filename, - ErrorHandler errorHandler, StreamRDF sink) { - this.reader = reader; - this.base = base; - this.filename = filename; - this.sink = sink; - this.profile = RiotLib.profile(getLang(), base, errorHandler); - } - - public LangCSV(InputStream in, String base, String filename, - ErrorHandler errorHandler, StreamRDF sink) { - this.input = in; - this.base = base; - this.filename = filename; - this.sink = sink; - this.profile = RiotLib.profile(getLang(), base, errorHandler); - } - - @Override - public void parse() { - sink.start(); - CSVParser parser = (input != null) ? CSVParser.create(input) - : CSVParser.create(reader); - List<String> row = null; - ArrayList<Node> predicates = new ArrayList<Node>(); - int rowNum = 0; - while ((row = parser.parse1()) != null) { - - if (rowNum == 0) { - for (String column : row) { - String uri = IRIResolver.resolveString(filename) + "#" - + toSafeLocalname(column); - Node predicate = this.profile.createURI(uri, rowNum, 0); - predicates.add(predicate); - } - } else { - //Node subject = this.profile.createBlankNode(null, -1, -1); - Node subject = caculateSubject(rowNum, filename); - Node predicateRow = this.profile.createURI(CSV_ROW, -1, -1); - Node objectRow = this.profile - .createTypedLiteral((rowNum + ""), - XSDDatatype.XSDinteger, rowNum, 0); - sink.triple(this.profile.createTriple(subject, predicateRow, - objectRow, rowNum, 0)); - for (int col = 0; col < row.size() && col<predicates.size(); col++) { - Node predicate = predicates.get(col); - String columnValue = row.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); - } - sink.triple(this.profile.createTriple(subject, predicate, - o, rowNum, col)); - } - - } - rowNum++; - } - sink.finish(); - - } - - public static String toSafeLocalname(String raw) { - String ret = raw.trim(); - return encodeURIComponent(ret); - - } - - public static String encodeURIComponent(String s) { - return IRILib.encodeUriComponent(s); - } - - public static Node caculateSubject(int rowNum, String filename){ - Node subject = NodeFactory.createAnon(); -// String uri = IRIResolver.resolveString(filename) + "#Row_" + rowNum; -// Node subject = NodeFactory.createURI(uri); - return subject; - } - - - - - private static class ReaderRIOTFactoryCSV implements ReaderRIOTFactory - { - @Override - public ReaderRIOT create(Lang lang) { - return new ReaderRIOTLangCSV(lang) ; - } - } - - private static class ReaderRIOTLangCSV implements ReaderRIOT - { - private final Lang lang ; - private ErrorHandler errorHandler ; - private ParserProfile parserProfile = null ; - - ReaderRIOTLangCSV(Lang lang) { - this.lang = lang ; - errorHandler = ErrorHandlerFactory.getDefaultErrorHandler() ; - } - - @Override - public void read(InputStream in, String baseURI, ContentType ct, StreamRDF output, Context context) { - if ( lang == CSV){ - LangRIOT parser = new LangCSV (in, baseURI, baseURI, ErrorHandlerFactory.getDefaultErrorHandler(), output); - if ( parserProfile != null ) - parser.setProfile(parserProfile); - if ( errorHandler != null ) - parser.getProfile().setHandler(errorHandler) ; - parser.parse() ; - } else { - throw new IllegalArgumentException("The Lang must be 'CSV'!"); - } - - } - - @Override - public void read(Reader in, String baseURI, ContentType ct, StreamRDF output, Context context) { - if ( lang == CSV){ - LangRIOT parser = new LangCSV (in, baseURI, baseURI, ErrorHandlerFactory.getDefaultErrorHandler(), output); - if ( parserProfile != null ) - parser.setProfile(parserProfile); - if ( errorHandler != null ) - parser.getProfile().setHandler(errorHandler) ; - parser.parse() ; - } else { - throw new IllegalArgumentException("The Lang must be 'CSV'!"); - } - } - - @Override public ErrorHandler getErrorHandler() { return errorHandler ; } - @Override public void setErrorHandler(ErrorHandler errorHandler) { this.errorHandler = errorHandler ; } - - @Override public ParserProfile getParserProfile() { return parserProfile ; } - @Override public void setParserProfile(ParserProfile parserProfile) { this.parserProfile = parserProfile ; } - } -}
