From: <mrp...@us...> - 2014-01-26 20:37:39
|
Revision: 7829 http://bigdata.svn.sourceforge.net/bigdata/?rev=7829&view=rev Author: mrpersonick Date: 2014-01-26 20:37:25 +0000 (Sun, 26 Jan 2014) Log Message: ----------- major commit of RDR. one step away from entirely removing the overloading of the context position for sids. working checkpoint. Modified Paths: -------------- branches/RDR/.classpath branches/RDR/bigdata/src/resources/logging/log4j.properties branches/RDR/bigdata-gas/src/test/com/bigdata/rdf/graph/data/smallGraph.ttl branches/RDR/bigdata-rdf/src/java/com/bigdata/rdf/internal/IVUtility.java branches/RDR/bigdata-rdf/src/java/com/bigdata/rdf/internal/LexiconConfiguration.java branches/RDR/bigdata-rdf/src/java/com/bigdata/rdf/model/BNodeContextFactory.java branches/RDR/bigdata-rdf/src/java/com/bigdata/rdf/model/BigdataBNode.java branches/RDR/bigdata-rdf/src/java/com/bigdata/rdf/model/BigdataBNodeImpl.java branches/RDR/bigdata-rdf/src/java/com/bigdata/rdf/model/BigdataStatementImpl.java branches/RDR/bigdata-rdf/src/java/com/bigdata/rdf/model/BigdataValueFactory.java branches/RDR/bigdata-rdf/src/java/com/bigdata/rdf/model/BigdataValueFactoryImpl.java branches/RDR/bigdata-rdf/src/java/com/bigdata/rdf/model/BigdataValueImpl.java branches/RDR/bigdata-rdf/src/java/com/bigdata/rdf/rio/BasicRioLoader.java branches/RDR/bigdata-rdf/src/java/com/bigdata/rdf/rio/StatementBuffer.java branches/RDR/bigdata-rdf/src/java/com/bigdata/rdf/rio/ntriples/BigdataNTriplesParser.java branches/RDR/bigdata-rdf/src/java/com/bigdata/rdf/rio/rdfxml/BigdataRDFXMLParser.java branches/RDR/bigdata-rdf/src/java/com/bigdata/rdf/rio/turtle/BigdataTurtleParser.java branches/RDR/bigdata-rdf/src/java/com/bigdata/rdf/sparql/ast/service/history/HistoryIndexTupleSerializer.java branches/RDR/bigdata-rdf/src/java/com/bigdata/rdf/spo/ISPO.java branches/RDR/bigdata-rdf/src/java/com/bigdata/rdf/spo/SPO.java branches/RDR/bigdata-rdf/src/java/com/bigdata/rdf/spo/SPOTupleSerializer.java branches/RDR/bigdata-rdf/src/java/com/bigdata/rdf/store/AbstractTripleStore.java branches/RDR/bigdata-rdf/src/test/com/bigdata/rdf/graph/impl/bd/TestBFS.java branches/RDR/bigdata-rdf/src/test/com/bigdata/rdf/internal/TestEncodeDecodeKeys.java branches/RDR/bigdata-rdf/src/test/com/bigdata/rdf/internal/TestEncodeDecodeMixedIVs.java branches/RDR/bigdata-rdf/src/test/com/bigdata/rdf/rio/TestNTriplesWithSids.java branches/RDR/bigdata-rdf/src/test/com/bigdata/rdf/rio/TestRDFXMLInterchangeWithStatementIdentifiers.java branches/RDR/bigdata-rdf/src/test/com/bigdata/rdf/rio/TestStatementBuffer.java branches/RDR/bigdata-rdf/src/test/com/bigdata/rdf/sparql/ast/optimizers/TestALPPinTrac773.java branches/RDR/bigdata-rdf/src/test/com/bigdata/rdf/sparql/ast/optimizers/TestASTNamedSubqueryOptimizer.java branches/RDR/bigdata-rdf/src/test/com/bigdata/rdf/sparql/ast/optimizers/TestASTUnionFiltersOptimizer.java branches/RDR/bigdata-rdf/src/test/com/bigdata/rdf/spo/TestSPO.java branches/RDR/bigdata-rdf/src/test/com/bigdata/rdf/spo/TestSPOTupleSerializer.java branches/RDR/bigdata-rdf/src/test/com/bigdata/rdf/spo/TestSPOValueCoders.java branches/RDR/bigdata-rdf/src/test/com/bigdata/rdf/store/TestStatementIdentifiers.java branches/RDR/bigdata-sails/src/test/com/bigdata/rdf/sail/TestProvenanceQuery.java Added Paths: ----------- branches/RDR/bigdata-rdf/src/java/com/bigdata/rdf/internal/impl/uri/IPAddrIV.java Modified: branches/RDR/.classpath =================================================================== --- branches/RDR/.classpath 2014-01-24 23:39:36 UTC (rev 7828) +++ branches/RDR/.classpath 2014-01-26 20:37:25 UTC (rev 7829) @@ -33,7 +33,7 @@ <classpathentry kind="src" path="bigdata-gas/src/test"/> <classpathentry exported="true" kind="lib" path="bigdata/lib/dsi-utils-1.0.6-020610.jar"/> <classpathentry exported="true" kind="lib" path="bigdata/lib/lgpl-utils-1.0.6-020610.jar"/> - <classpathentry kind="lib" path="bigdata-jini/lib/apache/zookeeper-3.3.3.jar"/> + <classpathentry exported="true" kind="lib" path="bigdata-jini/lib/apache/zookeeper-3.3.3.jar"/> <classpathentry exported="true" kind="lib" path="bigdata/lib/jetty/jetty-continuation-7.2.2.v20101205.jar"/> <classpathentry exported="true" kind="lib" path="bigdata/lib/jetty/jetty-http-7.2.2.v20101205.jar"/> <classpathentry exported="true" kind="lib" path="bigdata/lib/jetty/jetty-io-7.2.2.v20101205.jar"/> @@ -45,8 +45,8 @@ <classpathentry exported="true" kind="lib" path="bigdata/lib/jetty/jetty-webapp-7.2.2.v20101205.jar"/> <classpathentry exported="true" kind="lib" path="bigdata/lib/jetty/jetty-xml-7.2.2.v20101205.jar"/> <classpathentry exported="true" kind="lib" path="bigdata/lib/unimi/colt-1.2.0.jar"/> - <classpathentry kind="lib" path="bigdata/lib/icu/icu4j-4.8.jar"/> - <classpathentry kind="lib" path="bigdata/lib/icu/icu4j-charset-4.8.jar"/> + <classpathentry exported="true" kind="lib" path="bigdata/lib/icu/icu4j-4.8.jar"/> + <classpathentry exported="true" kind="lib" path="bigdata/lib/icu/icu4j-charset-4.8.jar"/> <classpathentry exported="true" kind="lib" path="bigdata/lib/junit-3.8.1.jar" sourcepath="/root/.m2/repository/junit/junit/3.8.1/junit-3.8.1-sources.jar"/> <classpathentry exported="true" kind="lib" path="bigdata-jini/lib/jini/lib/browser.jar"/> <classpathentry exported="true" kind="lib" path="bigdata-jini/lib/jini/lib/classserver.jar"/> @@ -67,24 +67,24 @@ <classpathentry exported="true" kind="lib" path="bigdata/lib/unimi/fastutil-5.1.5.jar"/> <classpathentry exported="true" kind="lib" path="bigdata/lib/lucene/lucene-analyzers-3.0.0.jar"/> <classpathentry exported="true" kind="lib" path="bigdata/lib/lucene/lucene-core-3.0.0.jar"/> - <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> + <classpathentry exported="true" kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> <classpathentry exported="true" kind="lib" path="bigdata/lib/high-scale-lib-v1.1.2.jar"/> <classpathentry exported="true" kind="lib" path="bigdata/lib/junit-ext-1.1-b3-dev.jar"/> <classpathentry exported="true" kind="lib" path="bigdata-rdf/lib/slf4j-api-1.6.1.jar"/> <classpathentry exported="true" kind="lib" path="bigdata-rdf/lib/slf4j-log4j12-1.6.1.jar"/> - <classpathentry kind="lib" path="bigdata-sails/lib/httpcomponents/commons-codec-1.4.jar"/> - <classpathentry kind="lib" path="bigdata-sails/lib/httpcomponents/commons-logging-1.1.1.jar"/> - <classpathentry kind="lib" path="bigdata-sails/lib/httpcomponents/httpclient-4.1.3.jar"/> - <classpathentry kind="lib" path="bigdata-sails/lib/httpcomponents/httpclient-cache-4.1.3.jar"/> - <classpathentry kind="lib" path="bigdata-sails/lib/httpcomponents/httpcore-4.1.4.jar"/> - <classpathentry kind="lib" path="bigdata-sails/lib/httpcomponents/httpmime-4.1.3.jar"/> - <classpathentry kind="lib" path="bigdata-sails/lib/httpcomponents/commons-fileupload-1.2.2.jar"/> - <classpathentry kind="lib" path="bigdata-sails/lib/httpcomponents/commons-io-2.1.jar"/> - <classpathentry kind="lib" path="bigdata/lib/apache/log4j-1.2.17.jar"/> - <classpathentry kind="lib" path="bigdata-rdf/lib/openrdf-sesame-2.6.10-onejar.jar"/> - <classpathentry kind="lib" path="bigdata-rdf/lib/sesame-rio-testsuite-2.6.10.jar"/> - <classpathentry kind="lib" path="bigdata-sails/lib/sesame-sparql-testsuite-2.6.10.jar"/> - <classpathentry kind="lib" path="bigdata-sails/lib/sesame-store-testsuite-2.6.10.jar"/> - <classpathentry kind="lib" path="bigdata-rdf/lib/nxparser-1.2.3.jar"/> + <classpathentry exported="true" kind="lib" path="bigdata-sails/lib/httpcomponents/commons-codec-1.4.jar"/> + <classpathentry exported="true" kind="lib" path="bigdata-sails/lib/httpcomponents/commons-logging-1.1.1.jar"/> + <classpathentry exported="true" kind="lib" path="bigdata-sails/lib/httpcomponents/httpclient-4.1.3.jar"/> + <classpathentry exported="true" kind="lib" path="bigdata-sails/lib/httpcomponents/httpclient-cache-4.1.3.jar"/> + <classpathentry exported="true" kind="lib" path="bigdata-sails/lib/httpcomponents/httpcore-4.1.4.jar"/> + <classpathentry exported="true" kind="lib" path="bigdata-sails/lib/httpcomponents/httpmime-4.1.3.jar"/> + <classpathentry exported="true" kind="lib" path="bigdata-sails/lib/httpcomponents/commons-fileupload-1.2.2.jar"/> + <classpathentry exported="true" kind="lib" path="bigdata-sails/lib/httpcomponents/commons-io-2.1.jar"/> + <classpathentry exported="true" kind="lib" path="bigdata/lib/apache/log4j-1.2.17.jar"/> + <classpathentry exported="true" kind="lib" path="bigdata-rdf/lib/openrdf-sesame-2.6.10-onejar.jar"/> + <classpathentry exported="true" kind="lib" path="bigdata-rdf/lib/sesame-rio-testsuite-2.6.10.jar"/> + <classpathentry exported="true" kind="lib" path="bigdata-sails/lib/sesame-sparql-testsuite-2.6.10.jar"/> + <classpathentry exported="true" kind="lib" path="bigdata-sails/lib/sesame-store-testsuite-2.6.10.jar"/> + <classpathentry exported="true" kind="lib" path="bigdata-rdf/lib/nxparser-1.2.3.jar"/> <classpathentry kind="output" path="bin"/> </classpath> Modified: branches/RDR/bigdata/src/resources/logging/log4j.properties =================================================================== --- branches/RDR/bigdata/src/resources/logging/log4j.properties 2014-01-24 23:39:36 UTC (rev 7828) +++ branches/RDR/bigdata/src/resources/logging/log4j.properties 2014-01-26 20:37:25 UTC (rev 7829) @@ -16,9 +16,13 @@ log4j.logger.com.bigdata.rdf.store.DataLoader=INFO log4j.logger.com.bigdata.resources.AsynchronousOverflowTask=INFO +#log4j.logger.com.bigdata.rdf.rio.StatementBuffer=ALL +#log4j.logger.com.bigdata.rdf.sail.TestProvenanceQuery=ALL + # Test suite loggers. #log4j.logger.junit=INFO #log4j.logger.com.bigdata.btree.AbstractBTreeTestCase=INFO +log4j.logger.junit.framework.TestCase2=ERROR # dest1 log4j.appender.dest1=org.apache.log4j.ConsoleAppender Modified: branches/RDR/bigdata-gas/src/test/com/bigdata/rdf/graph/data/smallGraph.ttl =================================================================== --- branches/RDR/bigdata-gas/src/test/com/bigdata/rdf/graph/data/smallGraph.ttl 2014-01-24 23:39:36 UTC (rev 7828) +++ branches/RDR/bigdata-gas/src/test/com/bigdata/rdf/graph/data/smallGraph.ttl 2014-01-26 20:37:25 UTC (rev 7829) @@ -1,19 +1,19 @@ -@prefix : <http://www.bigdata.com/> . +@prefix bd: <http://www.bigdata.com/> . @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> . @prefix foaf: <http://xmlns.com/foaf/0.1/> . #: { - :Mike rdf:type foaf:Person . - :Bryan rdf:type foaf:Person . - :Martyn rdf:type foaf:Person . + bd:Mike rdf:type foaf:Person . + bd:Bryan rdf:type foaf:Person . + bd:Martyn rdf:type foaf:Person . - :Mike rdfs:label "Mike" . - :Bryan rdfs:label "Bryan" . - :DC rdfs:label "DC" . + bd:Mike rdfs:label "Mike" . + bd:Bryan rdfs:label "Bryan" . + bd:DC rdfs:label "DC" . - :Mike foaf:knows :Bryan . - :Bryan foaf:knows :Mike . - :Bryan foaf:knows :Martyn . - :Martyn foaf:knows :Bryan . + bd:Mike foaf:knows bd:Bryan . + bd:Bryan foaf:knows bd:Mike . + bd:Bryan foaf:knows bd:Martyn . + bd:Martyn foaf:knows bd:Bryan . #} Modified: branches/RDR/bigdata-rdf/src/java/com/bigdata/rdf/internal/IVUtility.java =================================================================== --- branches/RDR/bigdata-rdf/src/java/com/bigdata/rdf/internal/IVUtility.java 2014-01-24 23:39:36 UTC (rev 7828) +++ branches/RDR/bigdata-rdf/src/java/com/bigdata/rdf/internal/IVUtility.java 2014-01-26 20:37:25 UTC (rev 7829) @@ -35,6 +35,8 @@ import java.io.IOException; import java.math.BigDecimal; import java.math.BigInteger; +import java.net.InetAddress; +import java.net.UnknownHostException; import java.util.LinkedList; import java.util.List; import java.util.UUID; @@ -66,6 +68,7 @@ import com.bigdata.rdf.internal.impl.literal.XSDUnsignedLongIV; import com.bigdata.rdf.internal.impl.literal.XSDUnsignedShortIV; import com.bigdata.rdf.internal.impl.uri.FullyInlineURIIV; +import com.bigdata.rdf.internal.impl.uri.IPAddrIV; import com.bigdata.rdf.internal.impl.uri.PartlyInlineURIIV; import com.bigdata.rdf.internal.impl.uri.URIExtensionIV; import com.bigdata.rdf.internal.impl.uri.VocabURIByteIV; @@ -437,7 +440,7 @@ final ISPO spo = SPOKeyOrder.SPO.decodeKey(key, o); // all spos that have a sid are explicit spo.setStatementType(StatementEnum.Explicit); - spo.setStatementIdentifier(true); +// spo.setStatementIdentifier(true); // create a sid iv and return it return new SidIV(spo); } @@ -535,6 +538,21 @@ // The data type final DTE dte = AbstractIV.getDTE(flags); switch (dte) { + case XSDBoolean: { + /* + * TODO Using XSDBoolean so that we can know how to decode this thing + * as an IPAddrIV. We need to fix the Extension mechanism for URIs. + * Extension is already used above. + */ + try { + final byte[] addr = new byte[4]; + System.arraycopy(key, o, addr, 0, 4); + final InetAddress ip = InetAddress.getByAddress(addr); + return new IPAddrIV(ip); + } catch (UnknownHostException ex) { + throw new RuntimeException(ex); + } + } case XSDByte: { final byte x = key[o];//KeyBuilder.decodeByte(key[o]); return new VocabURIByteIV<BigdataURI>(x); Modified: branches/RDR/bigdata-rdf/src/java/com/bigdata/rdf/internal/LexiconConfiguration.java =================================================================== --- branches/RDR/bigdata-rdf/src/java/com/bigdata/rdf/internal/LexiconConfiguration.java 2014-01-24 23:39:36 UTC (rev 7828) +++ branches/RDR/bigdata-rdf/src/java/com/bigdata/rdf/internal/LexiconConfiguration.java 2014-01-26 20:37:25 UTC (rev 7829) @@ -28,6 +28,7 @@ package com.bigdata.rdf.internal; import java.math.BigInteger; +import java.net.UnknownHostException; import java.util.LinkedHashMap; import java.util.Map; import java.util.TimeZone; @@ -58,6 +59,7 @@ import com.bigdata.rdf.internal.impl.literal.XSDUnsignedLongIV; import com.bigdata.rdf.internal.impl.literal.XSDUnsignedShortIV; import com.bigdata.rdf.internal.impl.uri.FullyInlineURIIV; +import com.bigdata.rdf.internal.impl.uri.IPAddrIV; import com.bigdata.rdf.internal.impl.uri.URIExtensionIV; import com.bigdata.rdf.lexicon.LexiconKeyOrder; import com.bigdata.rdf.model.BigdataBNode; @@ -435,6 +437,22 @@ */ private IV<BigdataURI, ?> createInlineURIIV(final URI value) { + try { + + final String s = value.stringValue(); + + if (s.startsWith(IPAddrIV.NAMESPACE)) { + + return new IPAddrIV(s.substring(IPAddrIV.NAMESPACE_LEN)); + + } + + } catch (UnknownHostException ex) { + + log.warn("unknown host exception, will not inline: " + value); + + } + if (maxInlineTextLength == 0) { return null; Added: branches/RDR/bigdata-rdf/src/java/com/bigdata/rdf/internal/impl/uri/IPAddrIV.java =================================================================== --- branches/RDR/bigdata-rdf/src/java/com/bigdata/rdf/internal/impl/uri/IPAddrIV.java (rev 0) +++ branches/RDR/bigdata-rdf/src/java/com/bigdata/rdf/internal/impl/uri/IPAddrIV.java 2014-01-26 20:37:25 UTC (rev 7829) @@ -0,0 +1,349 @@ +/** + +Copyright (C) SYSTAP, LLC 2006-2011. All rights reserved. + +Contact: + SYSTAP, LLC + 4501 Tower Road + Greensboro, NC 27410 + lic...@bi... + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; version 2 of the License. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ +package com.bigdata.rdf.internal.impl.uri; + +import java.io.Externalizable; +import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectOutput; +import java.io.ObjectStreamException; +import java.io.Serializable; +import java.net.InetAddress; +import java.net.UnknownHostException; + +import org.openrdf.model.URI; +import org.openrdf.model.Value; + +import com.bigdata.btree.BytesUtil.UnsignedByteArrayComparator; +import com.bigdata.btree.keys.IKeyBuilder; +import com.bigdata.io.LongPacker; +import com.bigdata.rdf.internal.DTE; +import com.bigdata.rdf.internal.ILexiconConfiguration; +import com.bigdata.rdf.internal.IV; +import com.bigdata.rdf.internal.IVUtility; +import com.bigdata.rdf.internal.VTE; +import com.bigdata.rdf.internal.impl.AbstractInlineIV; +import com.bigdata.rdf.lexicon.LexiconRelation; +import com.bigdata.rdf.model.BigdataBNode; +import com.bigdata.rdf.model.BigdataURI; +import com.bigdata.rdf.model.BigdataValueFactory; +import com.bigdata.rdf.spo.SPOKeyOrder; + +/** + * Internal value representing an inline IP address. Uses the InetAddress + * class to represent the IP address and perform the translation to and from + * byte[], which is then used directly in the IV key (after the flags). + * <p> + * This internal value has a {@link VTE} of {@link VTE#URI}. + * <p> + * {@inheritDoc} + */ +public class IPAddrIV<V extends BigdataURI> extends AbstractInlineIV<V, InetAddress> + implements Serializable, URI { + + /** + * + */ + private static final long serialVersionUID = 685148537376856907L; + +// private static final transient Logger log = Logger.getLogger(SidIV.class); + + public static final String NAMESPACE = "ip:/"; + + public static final int NAMESPACE_LEN = NAMESPACE.length(); + + /** + * The inline IP address. + */ + private final InetAddress value; + + /** + * The cached string representation of this IP. + */ + private transient String hostAddress; + + /** + * The cached byte[] key for the encoding of this IV. + */ + private transient byte[] key; + + /** + * The cached materialized BigdataValue for this InetAddress. + */ + private transient V uri; + + public IV<V, InetAddress> clone(final boolean clearCache) { + + final IPAddrIV<V> tmp = new IPAddrIV<V>(value); + + // Propagate the cached byte[] key. + tmp.key = key; + + // Propagate the cached BigdataValue. + tmp.uri = uri; + + if (!clearCache) { + + tmp.setValue(getValueCache()); + + } + + return tmp; + + } + + /** + * Ctor with internal value specified. + */ + public IPAddrIV(final InetAddress value) { + + /* + * TODO Using XSDBoolean so that we can know how to decode this thing + * as an IPAddrIV. We need to fix the Extension mechanism for URIs. + */ + super(VTE.URI, DTE.XSDBoolean); + + this.value = value; + + } + + /** + * Ctor with host address specified. + */ + public IPAddrIV(final String hostAddress) throws UnknownHostException { + + /* + * Note: XSDBoolean happens to be assigned the code value of 0, which is + * the value we we want when the data type enumeration will be ignored. + */ + super(VTE.URI, DTE.XSDBoolean); + + this.value = InetAddress.getByName(hostAddress); + this.hostAddress = hostAddress; + + } + + /** + * Returns the inline value. + */ + public InetAddress getInlineValue() throws UnsupportedOperationException { + return value; + } + + /** + * Returns the URI representation of this IV. + */ + public V asValue(final LexiconRelation lex) { + if (uri == null) { + uri = (V) lex.getValueFactory().createURI(getNamespace(), getLocalName()); + uri.setIV(this); + } + return uri; + } + + /** + * Return the byte length for the byte[] encoded representation of this + * internal value. Depends on the byte length of the encoded inline value. + */ + public int byteLength() { + return 1 + key().length; + } + + public String toString() { + return "IP("+getLocalName()+")"; + } + + public int hashCode() { + return value.hashCode(); + } + +// /** +// * Implements {@link BNode#getID()}. +// * <p> +// * This implementation uses the {@link BigInteger} class to create a unique +// * blank node ID based on the <code>unsigned byte[]</code> key of the inline +// * {@link SPO}. +// */ +// @Override +// public String getID() { +//// // just use the hash code. can result in collisions +//// return String.valueOf(hashCode()); +// +// // create a big integer using the spo key. should result in unique ids +// final byte[] key = key(); +// final int signum = key.length > 0 ? 1 : 0; +// final BigInteger bi = new BigInteger(signum, key); +// return 's' + bi.toString(); +// } + + @Override + public String getNamespace() { + return NAMESPACE; + } + + @Override + public String getLocalName() { + if (hostAddress == null) { + hostAddress = value.getHostAddress(); + } + return hostAddress; + } + + /** + * Two {@link IPAddrIV} are equal if their InetAddresses are equal. + */ + public boolean equals(final Object o) { + if (this == o) + return true; + if (o instanceof IPAddrIV) { + final InetAddress value2 = ((IPAddrIV<?>) o).value; + return value.equals(value2); + } + return false; + } + + public int _compareTo(IV o) { + + /* + * Note: This works, but it might be more expensive. + */ + return UnsignedByteArrayComparator.INSTANCE.compare(key(), ((IPAddrIV)o).key()); + + } + + /** + * Encode this internal value into the supplied key builder. Emits the + * flags, following by the encoded byte[] representing the spo, in SPO + * key order. + * <p> + * {@inheritDoc} + */ + @Override + public IKeyBuilder encode(final IKeyBuilder keyBuilder) { + + // First emit the flags byte. + keyBuilder.appendSigned(flags()); + + // Then append the InetAddress byte[]. + keyBuilder.append(key()); + + return keyBuilder; + + } + + private byte[] key() { + + if (key == null) { + + key = value.getAddress(); + + } + + return key; + + } + + /** + * Object provides serialization for {@link IPAddrIV} via the write-replace + * and read-replace pattern. + */ + private static class IPAddrIVState implements Externalizable { + + private static final long serialVersionUID = -1L; + +// private byte flags; + private byte[] key; + + /** + * De-serialization constructor. + */ + public IPAddrIVState() { + + } + + private IPAddrIVState(final IPAddrIV iv) { +// this.flags = flags; + this.key = iv.key(); + } + + public void readExternal(ObjectInput in) throws IOException, + ClassNotFoundException { +// flags = in.readByte(); + final int nbytes = LongPacker.unpackInt(in); + key = new byte[nbytes]; + in.readFully(key); + } + + public void writeExternal(ObjectOutput out) throws IOException { +// out.writeByte(flags); + LongPacker.packLong(out, key.length); + out.write(key); + } + + private Object readResolve() throws ObjectStreamException { + + try { + + final InetAddress value = InetAddress.getByAddress(key); + + return new IPAddrIV(value); + + } catch (UnknownHostException ex) { + + throw new RuntimeException(ex); + + } + + } + + } + + private Object writeReplace() throws ObjectStreamException { + + return new IPAddrIVState(this); + + } + + /** + * Implements {@link Value#stringValue()}. + */ + @Override + public String stringValue() { + + return getLocalName(); + + } + + /** + * Does not need materialization to answer URI interface methods. + */ + @Override + public boolean needsMaterialization() { + + return false; + + } + + +} \ No newline at end of file Property changes on: branches/RDR/bigdata-rdf/src/java/com/bigdata/rdf/internal/impl/uri/IPAddrIV.java ___________________________________________________________________ Added: svn:mime-type + text/plain Modified: branches/RDR/bigdata-rdf/src/java/com/bigdata/rdf/model/BNodeContextFactory.java =================================================================== --- branches/RDR/bigdata-rdf/src/java/com/bigdata/rdf/model/BNodeContextFactory.java 2014-01-24 23:39:36 UTC (rev 7828) +++ branches/RDR/bigdata-rdf/src/java/com/bigdata/rdf/model/BNodeContextFactory.java 2014-01-26 20:37:25 UTC (rev 7829) @@ -89,6 +89,10 @@ return valueFactory.createBNode(id); } + public BigdataBNode createBNode(BigdataStatement stmt) { + return valueFactory.createBNode(stmt); + } + public BigdataLiteral createLiteral(boolean arg0) { return valueFactory.createLiteral(arg0); } Modified: branches/RDR/bigdata-rdf/src/java/com/bigdata/rdf/model/BigdataBNode.java =================================================================== --- branches/RDR/bigdata-rdf/src/java/com/bigdata/rdf/model/BigdataBNode.java 2014-01-24 23:39:36 UTC (rev 7828) +++ branches/RDR/bigdata-rdf/src/java/com/bigdata/rdf/model/BigdataBNode.java 2014-01-26 20:37:25 UTC (rev 7829) @@ -67,4 +67,14 @@ */ public boolean isStatementIdentifier(); + /** + * Set the statement that this blank node models. + */ + public void setStatement(BigdataStatement stmt); + + /** + * Get the statement that this blank node models. + */ + public BigdataStatement getStatement(); + } Modified: branches/RDR/bigdata-rdf/src/java/com/bigdata/rdf/model/BigdataBNodeImpl.java =================================================================== --- branches/RDR/bigdata-rdf/src/java/com/bigdata/rdf/model/BigdataBNodeImpl.java 2014-01-24 23:39:36 UTC (rev 7828) +++ branches/RDR/bigdata-rdf/src/java/com/bigdata/rdf/model/BigdataBNodeImpl.java 2014-01-26 20:37:25 UTC (rev 7829) @@ -49,7 +49,10 @@ import org.openrdf.model.BNode; +import com.bigdata.rdf.internal.IV; +import com.bigdata.rdf.internal.impl.bnode.SidIV; import com.bigdata.rdf.rio.StatementBuffer; +import com.bigdata.rdf.rio.UnificationException; import com.bigdata.rdf.spo.SPO; import com.bigdata.rdf.store.AbstractTripleStore; @@ -76,7 +79,7 @@ private static final long serialVersionUID = 2675602437833048872L; private final String id; - + /** * Boolean flag is set during conversion from an RDF interchange syntax * into the internal {@link SPO} model if the blank node is a statement @@ -95,14 +98,45 @@ */ BigdataBNodeImpl(final BigdataValueFactory valueFactory, final String id) { + this(valueFactory, id, null); + + } + + BigdataBNodeImpl(final BigdataValueFactory valueFactory, final String id, + final BigdataStatement stmt) { + super(valueFactory, null); if (id == null) throw new IllegalArgumentException(); this.id = id; + + this.sid = stmt; + if (stmt != null) { + this.statementIdentifier = true; + } } + + @Override + public IV getIV() { + + if (super.iv == null && sid != null) { + + if (sid.getSubject() == this || sid.getObject() == this) + throw new UnificationException("illegal self-referential sid"); + + final IV s = sid.s(); + final IV p = sid.p(); + final IV o = sid.o(); + if (s != null && p != null && o != null) { + setIV(new SidIV(new SPO(s, p, o))); + } + } + + return super.iv; + } public String toString() { @@ -179,7 +213,7 @@ /** * Marks this as a blank node which models the specified statement. * - * @param stmt + * @param sid * The statement. */ final public void setStatement(final BigdataStatement sid) { Modified: branches/RDR/bigdata-rdf/src/java/com/bigdata/rdf/model/BigdataStatementImpl.java =================================================================== --- branches/RDR/bigdata-rdf/src/java/com/bigdata/rdf/model/BigdataStatementImpl.java 2014-01-24 23:39:36 UTC (rev 7828) +++ branches/RDR/bigdata-rdf/src/java/com/bigdata/rdf/model/BigdataStatementImpl.java 2014-01-26 20:37:25 UTC (rev 7829) @@ -63,6 +63,7 @@ protected final BigdataURI p; protected final BigdataValue o; protected final BigdataResource c; + protected IV sid = null; private StatementEnum type; private boolean userFlag; private transient boolean override = false; @@ -282,39 +283,51 @@ } - public final void setStatementIdentifier(final boolean sidable) { +// public final void setStatementIdentifier(final boolean sidable) { +// +// if (sidable && type != StatementEnum.Explicit) { +// +// // Only allowed for explicit statements. +// throw new IllegalStateException(); +// +// } +// +//// if (c == null) { +//// +//// // this SHOULD not ever happen +//// throw new IllegalStateException(); +//// +//// } +//// +//// c.setIV(new SidIV(this)); +// +// this.sid = new SidIV(this); +// +// } - if (sidable && type != StatementEnum.Explicit) { - - // Only allowed for explicit statements. - throw new IllegalStateException(); - - } - - if (c == null) { - - // this SHOULD not ever happen - throw new IllegalStateException(); - - } - - c.setIV(new SidIV(this)); - - } - public final IV getStatementIdentifier() { - if (!hasStatementIdentifier()) - throw new IllegalStateException("No statement identifier: " - + toString()); +// if (!hasStatementIdentifier()) +// throw new IllegalStateException("No statement identifier: " +// + toString()); +// +// return c.getIV(); - return c.getIV(); + if (sid == null && type == StatementEnum.Explicit) { + + sid = new SidIV(this); + + } + + return sid; } final public boolean hasStatementIdentifier() { - return c != null && c.getIV().isStatement(); +// return c != null && c.getIV().isStatement(); + + return type == StatementEnum.Explicit; } Modified: branches/RDR/bigdata-rdf/src/java/com/bigdata/rdf/model/BigdataValueFactory.java =================================================================== --- branches/RDR/bigdata-rdf/src/java/com/bigdata/rdf/model/BigdataValueFactory.java 2014-01-24 23:39:36 UTC (rev 7828) +++ branches/RDR/bigdata-rdf/src/java/com/bigdata/rdf/model/BigdataValueFactory.java 2014-01-26 20:37:25 UTC (rev 7829) @@ -85,6 +85,8 @@ BigdataBNode createBNode(); BigdataBNode createBNode(String id); + + BigdataBNode createBNode(BigdataStatement stmt); BigdataLiteral createLiteral(String label); Modified: branches/RDR/bigdata-rdf/src/java/com/bigdata/rdf/model/BigdataValueFactoryImpl.java =================================================================== --- branches/RDR/bigdata-rdf/src/java/com/bigdata/rdf/model/BigdataValueFactoryImpl.java 2014-01-24 23:39:36 UTC (rev 7828) +++ branches/RDR/bigdata-rdf/src/java/com/bigdata/rdf/model/BigdataValueFactoryImpl.java 2014-01-26 20:37:25 UTC (rev 7829) @@ -36,6 +36,7 @@ import org.openrdf.model.BNode; import org.openrdf.model.Literal; import org.openrdf.model.Resource; +import org.openrdf.model.Statement; import org.openrdf.model.URI; import org.openrdf.model.Value; import org.openrdf.model.datatypes.XMLDatatypeUtil; @@ -235,6 +236,12 @@ } + public BigdataBNodeImpl createBNode(final BigdataStatement stmt) { + + return new BigdataBNodeImpl(this, nextID(), stmt); + + } + public BigdataLiteralImpl createLiteral(final String label) { return new BigdataLiteralImpl(this, label, null, null); Modified: branches/RDR/bigdata-rdf/src/java/com/bigdata/rdf/model/BigdataValueImpl.java =================================================================== --- branches/RDR/bigdata-rdf/src/java/com/bigdata/rdf/model/BigdataValueImpl.java 2014-01-24 23:39:36 UTC (rev 7828) +++ branches/RDR/bigdata-rdf/src/java/com/bigdata/rdf/model/BigdataValueImpl.java 2014-01-26 20:37:25 UTC (rev 7829) @@ -48,7 +48,7 @@ private volatile transient BigdataValueFactory valueFactory; - private volatile IV iv; + protected volatile IV iv; public final BigdataValueFactory getValueFactory() { @@ -115,7 +115,7 @@ } - final public IV getIV() { + public IV getIV() { return iv; Modified: branches/RDR/bigdata-rdf/src/java/com/bigdata/rdf/rio/BasicRioLoader.java =================================================================== --- branches/RDR/bigdata-rdf/src/java/com/bigdata/rdf/rio/BasicRioLoader.java 2014-01-24 23:39:36 UTC (rev 7828) +++ branches/RDR/bigdata-rdf/src/java/com/bigdata/rdf/rio/BasicRioLoader.java 2014-01-26 20:37:25 UTC (rev 7829) @@ -153,6 +153,8 @@ final RDFParser parser = Rio.createParser(rdfFormat, valueFactory); + parser.setValueFactory(valueFactory); + return parser; } Modified: branches/RDR/bigdata-rdf/src/java/com/bigdata/rdf/rio/StatementBuffer.java =================================================================== --- branches/RDR/bigdata-rdf/src/java/com/bigdata/rdf/rio/StatementBuffer.java 2014-01-24 23:39:36 UTC (rev 7828) +++ branches/RDR/bigdata-rdf/src/java/com/bigdata/rdf/rio/StatementBuffer.java 2014-01-26 20:37:25 UTC (rev 7829) @@ -232,11 +232,11 @@ */ protected final int capacity; - /** - * When true only distinct terms are stored in the buffer (this is always - * true since this condition always outperforms the alternative). - */ - protected final boolean distinct = true; +// /** +// * When true only distinct terms are stored in the buffer (this is always +// * true since this condition always outperforms the alternative). +// */ +// protected final boolean distinct = true; public boolean isEmpty() { @@ -347,30 +347,22 @@ this.capacity = capacity; - values = new BigdataValue[capacity * arity]; + values = new BigdataValue[capacity * arity + 5]; stmts = new BigdataStatement[capacity]; - if (distinct) { - - /* - * initialize capacity to N times the #of statements allowed. this - * is the maximum #of distinct terms and would only be realized if - * each statement used distinct values. in practice the #of distinct - * terms will be much lower. however, also note that the map will be - * resized at .75 of the capacity so we want to over-estimate the - * maximum likely capacity by at least 25% to avoid re-building the - * hash map. - */ - - distinctTermMap = new HashMap<Value, BigdataValue>(capacity * arity); - - } else { - - distinctTermMap = null; - - } + /* + * initialize capacity to N times the #of statements allowed. this + * is the maximum #of distinct terms and would only be realized if + * each statement used distinct values. in practice the #of distinct + * terms will be much lower. however, also note that the map will be + * resized at .75 of the capacity so we want to over-estimate the + * maximum likely capacity by at least 25% to avoid re-building the + * hash map. + */ + distinctTermMap = new HashMap<Value, BigdataValue>(capacity * arity); + this.statementIdentifiers = database.getStatementIdentifiers(); if(log.isInfoEnabled()) { @@ -387,18 +379,14 @@ this.RDF_STATEMENT = valueFactory.asValue(RDF.STATEMENT); this.RDF_TYPE = valueFactory.asValue(RDF.TYPE); - if (distinct) { - - /* - * Get the reification vocabulary into the distinct term map. - */ - getDistinctTerm(RDF_SUBJECT); - getDistinctTerm(RDF_PREDICATE); - getDistinctTerm(RDF_OBJECT); - getDistinctTerm(RDF_STATEMENT); - getDistinctTerm(RDF_TYPE); - - } + /* + * Get the reification vocabulary into the distinct term map. + */ + getDistinctTerm(RDF_SUBJECT, true); + getDistinctTerm(RDF_PREDICATE, true); + getDistinctTerm(RDF_OBJECT, true); + getDistinctTerm(RDF_STATEMENT, true); + getDistinctTerm(RDF_TYPE, true); } @@ -415,8 +403,6 @@ */ public long flush() { - log.info(""); - /* * Process deferred statements (NOP unless using statement identifiers). */ @@ -552,11 +538,7 @@ while(itr.hasNext()) { final BigdataStatement stmt = itr.next(); - - if (log.isDebugEnabled()) { - log.debug(stmt.getSubject() + ", sid=" + ((BigdataBNode) stmt.getSubject()).isStatementIdentifier() + ", iv=" + stmt.s()); - } - + if (stmt.getSubject() instanceof BNode && ((BigdataBNode) stmt.getSubject()).isStatementIdentifier()) continue; @@ -569,6 +551,12 @@ log.debug("grounded: "+stmt); } + if (stmt.getSubject() instanceof BNode) + addTerm(stmt.getSubject()); + + if (stmt.getObject() instanceof BNode) + addTerm(stmt.getObject()); + // fully grounded so add to the buffer. add(stmt); @@ -703,8 +691,6 @@ */ public void reset() { - log.info(""); - _clear(); /* @@ -763,6 +749,15 @@ if (distinctTermMap != null) { distinctTermMap.clear(); + + /* + * Get the reification vocabulary into the distinct term map. + */ + getDistinctTerm(RDF_SUBJECT, true); + getDistinctTerm(RDF_PREDICATE, true); + getDistinctTerm(RDF_OBJECT, true); + getDistinctTerm(RDF_STATEMENT, true); + getDistinctTerm(RDF_TYPE, true); } @@ -775,6 +770,24 @@ */ protected void incrementalWrite() { + if (bnodes != null) { + + for (BigdataBNode bnode : bnodes.values()) { + + if (bnode.isStatementIdentifier()) + continue; + + if (bnode.getIV() != null) + continue; + + values[numValues++] = bnode; + + numBNodes++; + + } + + } + final long begin = System.currentTimeMillis(); if (log.isInfoEnabled()) { @@ -1177,9 +1190,10 @@ * @return Either the term or the pre-existing term in the buffer with the * same data. */ - protected BigdataValue getDistinctTerm(final BigdataValue term) { + protected BigdataValue getDistinctTerm(final BigdataValue term, final boolean addIfAbsent) { - assert distinct == true; + if (term == null) + return null; if (term instanceof BNode) { @@ -1193,65 +1207,125 @@ final BigdataBNode bnode = (BigdataBNode)term; - // the BNode's ID. - final String id = bnode.getID(); - - if (bnodes == null) { - - // allocating canonicalizing map for blank nodes. - bnodes = new HashMap<String, BigdataBNode>(capacity); - - // insert this blank node into the map. - bnodes.put(id, bnode); - + final BigdataStatement stmt = bnode.getStatement(); + + if (stmt != null) { + +// /* +// * Assume for now that bnodes appearing inside the terse +// * syntax without a statement attached are real bnodes, not +// * sids. +// */ +// final boolean tmp = this.statementIdentifiers; +// this.statementIdentifiers = false; + + bnode.setStatement(valueFactory.createStatement( + (BigdataResource) getDistinctTerm(stmt.getSubject(), true), + (BigdataURI) getDistinctTerm(stmt.getPredicate(), true), + (BigdataValue) getDistinctTerm(stmt.getObject(), true) + )); + +// this.statementIdentifiers = tmp; + + /* + * Do not "add if absent". This is not a real term, just a + * composition of other terms. + */ + return bnode; + } else { - - // test canonicalizing map for blank nodes. - final BigdataBNode existingBNode = bnodes.get(id); - - if (existingBNode != null) { - - // return existing blank node with same ID. - return existingBNode; - - } - - // insert this blank node into the map. - bnodes.put(id, bnode); - + + // the BNode's ID. + final String id = bnode.getID(); + + if (bnodes == null) { + + // allocating canonicalizing map for blank nodes. + bnodes = new HashMap<String, BigdataBNode>(capacity); + + // insert this blank node into the map. + bnodes.put(id, bnode); + + } else { + + // test canonicalizing map for blank nodes. + final BigdataBNode existingBNode = bnodes.get(id); + + if (existingBNode != null) { + + /* + * Return existing blank node with same ID, do not + * add since not absent. + */ + return existingBNode; + + } + + // insert this blank node into the map. + bnodes.put(id, bnode); + + } + } - return term; +// return term; - } + } else { - /* - * Other kinds of terms use a map whose scope is limited to the terms - * that are currently in the buffer. This keeps down the heap demand - * when reading very large documents. - */ - - final BigdataValue existingTerm = distinctTermMap.get(term); - - if(existingTerm != null) { - - // return the pre-existing term. - + /* + * Other kinds of terms use a map whose scope is limited to the terms + * that are currently in the buffer. This keeps down the heap demand + * when reading very large documents. + */ + + final BigdataValue existingTerm = distinctTermMap.get(term); + + if (existingTerm != null) { + + // return the pre-existing term. + + if(log.isDebugEnabled()) { + + log.debug("duplicate: "+term); + + } + + if (equals(existingTerm, RDF_SUBJECT, RDF_PREDICATE, RDF_OBJECT, RDF_TYPE, RDF_STATEMENT)) { + + if (addIfAbsent) { + + addTerm(term); + + } + + } + + /* + * Term already exists, do not add. + */ + return existingTerm; + + } + if(log.isDebugEnabled()) { - log.debug("duplicate: "+term); + log.debug("new term: "+term); } - return existingTerm; - + // put the new term in the map. + if (distinctTermMap.put(term, term) != null) { + + throw new AssertionError(); + + } + } - - // put the new term in the map. - if (distinctTermMap.put(term, term) != null) { - - throw new AssertionError(); - + + if (addIfAbsent) { + + addTerm(term); + } // return the new term. @@ -1259,6 +1333,37 @@ } + protected void addTerm(final BigdataValue term) { + + if (term == null) + return; + + if (term instanceof URI) { + + numURIs++; + + values[numValues++] = term; + + } else if (term instanceof BNode) { + +// if (!statementIdentifiers) { +// +// numBNodes++; +// +// values[numValues++] = term; +// +// } + + } else { + + numLiterals++; + + values[numValues++] = term; + + } + + } + /** * Adds the values and the statement into the buffer. * @@ -1278,244 +1383,126 @@ * * @see #nearCapacity() */ - protected void handleStatement(Resource s, URI p, Value o, Resource c, + protected void handleStatement(Resource _s, URI _p, Value _o, Resource _c, StatementEnum type) { + if (log.isDebugEnabled()) { + + log.debug("handle stmt: " + _s + ", " + _p + ", " + _o + ", " + _c); + + } + // if (arity == 3) c = null; - s = (Resource) valueFactory.asValue(s); - p = (URI) valueFactory.asValue(p); - o = valueFactory.asValue(o); - c = (Resource) valueFactory.asValue(c); + final BigdataResource s = (BigdataResource) + getDistinctTerm(valueFactory.asValue(_s), true); + final BigdataURI p = (BigdataURI) + getDistinctTerm(valueFactory.asValue(_p), true); + final BigdataValue o = + getDistinctTerm(valueFactory.asValue(_o), true); + final BigdataResource c = (BigdataResource) + getDistinctTerm(valueFactory.asValue(_c), true); - boolean duplicateS = false; - boolean duplicateP = false; - boolean duplicateO = false; - boolean duplicateC = false; - - if (distinct) { - { - final BigdataValue tmp = getDistinctTerm((BigdataValue) s); - if (tmp != s && !equals(tmp, RDF_SUBJECT, RDF_PREDICATE, RDF_OBJECT, RDF_TYPE, RDF_STATEMENT)) { - duplicateS = true; - } - s = (Resource) tmp; - } - { - final BigdataValue tmp = getDistinctTerm((BigdataValue) p); - if (tmp != p && !equals(tmp, RDF_SUBJECT, RDF_PREDICATE, RDF_OBJECT, RDF_TYPE)) { - duplicateP = true; - } - p = (URI) tmp; - } - { - final BigdataValue tmp = getDistinctTerm((BigdataValue) o); - if (tmp != o && !equals(tmp, RDF_SUBJECT, RDF_PREDICATE, RDF_OBJECT, RDF_TYPE, RDF_STATEMENT)) { - duplicateO = true; - } - o = (Value) tmp; - } - if (c != null) { - final BigdataValue tmp = getDistinctTerm((BigdataValue) c); - if (tmp != c) { - duplicateC = true; - } - c = (Resource) tmp; - } - } - /* * Form the BigdataStatement object now that we have the bindings. */ - final BigdataStatement stmt; - { - - stmt = valueFactory - .createStatement((BigdataResource) s, (BigdataURI) p, - (BigdataValue) o, (BigdataResource) c, type); + final BigdataStatement stmt = valueFactory.createStatement(s, p, o, c, type); - if (statementIdentifiers - && (s instanceof BNode || o instanceof BNode)) { + if (statementIdentifiers + && ((s instanceof BNode && ((BigdataBNode) s).getStatement() == null) +// || +// (o instanceof BNode && ((BigdataBNode) o).getStatement() == null) + )) { - /* - * When statement identifiers are enabled a statement with a - * blank node in the subject or object position must be deferred - * until the end of the source so that we determine whether it - * is being used as a statement identifier or a blank node (if - * the blank node occurs in the context position, then we know - * that it is being used as a statement identifier). - */ + /* + * When statement identifiers are enabled a statement with a + * blank node in the subject or object position must be deferred + * until the end of the source so that we determine whether it + * is being used as a statement identifier or a blank node (if + * the blank node occurs in the context position, then we know + * that it is being used as a statement identifier). + */ + + if (//s instanceof BNode && + equals(p, RDF_SUBJECT, RDF_PREDICATE, RDF_OBJECT)) { + + final BigdataBNodeImpl sid = (BigdataBNodeImpl) s; + + if (reifiedStmts == null) { + + reifiedStmts = new HashMap<BigdataBNodeImpl, ReifiedStmt>(); + + } + + final ReifiedStmt reifiedStmt; + if (reifiedStmts.containsKey(sid)) { + + reifiedStmt = reifiedStmts.get(sid); + + } else { + + reifiedStmt = new ReifiedStmt(); + + reifiedStmts.put(sid, reifiedStmt); + + } + + reifiedStmt.set(p, (BigdataValue) o); + + if (log.isDebugEnabled()) + log.debug("reified piece: "+stmt); - log.info(stmt); - - if (s instanceof BNode && - equals((BigdataValue)p, RDF_SUBJECT, RDF_PREDICATE, RDF_OBJECT)) { - - final BigdataBNodeImpl sid = (BigdataBNodeImpl) s; - - if (reifiedStmts == null) { - - reifiedStmts = new HashMap<BigdataBNodeImpl, ReifiedStmt>(); - - } - - final ReifiedStmt reifiedStmt; - if (reifiedStmts.containsKey(sid)) { - - reifiedStmt = reifiedStmts.get(sid); - - } else { - - reifiedStmt = new ReifiedStmt(); - - reifiedStmts.put(sid, reifiedStmt); - - } - - reifiedStmt.set(p, (BigdataValue) o); - - if (log.isDebugEnabled()) - log.debug("reified piece: "+stmt); - - } else if (s instanceof BNode && - equals((BigdataValue)o, RDF_STATEMENT) && equals((BigdataValue)p, RDF_TYPE)) { - - // ignore this statement - - } else { - - if (deferredStmts == null) { - - deferredStmts = new HashSet<BigdataStatement>(stmts.length); - - } - - deferredStmts.add(stmt); - - if (log.isDebugEnabled()) - log.debug("deferred: "+stmt); - - } + if (reifiedStmt.isFullyBound(arity)) { + + sid.setStatement(reifiedStmt.toStatement(valueFactory)); + + reifiedStmts.remove(sid); + + } - } else { + return; - // add to the buffer. - stmts[numStmts++] = stmt; + } +// else { +// +// if (deferredStmts == null) { +// +// deferredStmts = new HashSet<BigdataStatement>(stmts.length); +// +// } +// +// deferredStmts.add(stmt); +// +// if (log.isDebugEnabled()) +// log.debug("deferred: "+stmt); +// +// } +// +// } else { - } - } - - /* - * Update counters. - */ - if (!duplicateS) {// && ((_Value) s).termId == 0L) { + if (statementIdentifiers && s instanceof BNode && + equals(o, RDF_STATEMENT) && equals(p, RDF_TYPE)) { + + // ignore this statement + + return; + + } + + // add to the buffer. + stmts[numStmts++] = stmt; - if (s instanceof URI) { +// } - numURIs++; - - values[numValues++] = (BigdataValue) s; - - } else { - - if (!statementIdentifiers) { - - numBNodes++; - - values[numValues++] = (BigdataValue) s; - - } - - } - + if (c != null && statementIdentifiers && c instanceof BNode) { + + ((BigdataBNodeImpl) c).setStatement(stmt); + } - if (!duplicateP) {//&& ((_Value) s).termId == 0L) { - - values[numValues++] = (BigdataValue)p; - - numURIs++; - - } - - if (!duplicateO) {// && ((_Value) s).termId == 0L) { - - if (o instanceof URI) { - - numURIs++; - - values[numValues++] = (BigdataValue) o; - - } else if (o instanceof BNode) { - - if (!statementIdentifiers) { - - numBNodes++; - - values[numValues++] = (BigdataValue) o; - - } - - } else { - - numLiterals++; - - values[numValues++] = (BigdataValue) o; - - } - - } - - if (c != null && !duplicateC && ((BigdataValue) c).getIV() == null) { - - if (c instanceof URI) { - - numURIs++; - - values[numValues++] = (BigdataValue) c; - - } else { - - if (!database.getStatementIdentifiers()) { - - /* - * We only let the context node into the buffer when - * statement identifiers are disabled for the database. - * - * Note: This does NOT test [statementIdentifiers] as that - * flag is temporarily overriden when processing deferred - * statements. - */ - - values[numValues++] = (BigdataValue) c; - - numBNodes++; - - } else { - - /* - * Flag the blank node as a statement identifier since it - * appears in the context position. - * - * Note: the blank node is not inserted into values[] since - * it is a statement identifier and will be assigned when we - * insert the statement rather than based on the blank - * node's ID. - */ - - // Note: done automatically by setStatement(); -// ((BigdataBNode) c).setStatementIdentifier( true); - ((BigdataBNodeImpl) c).setStatement(stmt); - - } - - } - - } - } private boolean equals(final BigdataValue v1, final BigdataValue... v2) { @@ -1541,15 +1528,17 @@ private boolean _equals(final BigdataValue v1, final BigdataValue v2) { - if (distinct) { - - return v1 == v2; - - } else { - - return v1.equals(v2); - - } + return v1 == v2; + +// if (distinct) { +// +// return v1 == v2; +// +// } else { +// +// return v1.equals(v2); +// +// } } @@ -1639,6 +1628,12 @@ return "<" + s + ", " + p + ", " + o + ", " + c + ">"; } + + public BigdataStatement toStatement(final BigdataValueFactory vf) { + + return vf.createStatement(s, p, o, c); + + } } Modified: branches/RDR/bigdata-rdf/src/java/com/bigdata/rdf/rio/ntriples/BigdataNTriplesParser.java =================================================================== --- branches/RDR/bigdata-rdf/src/java/com/bigdata/rdf/rio/ntriples/BigdataNTriplesParser.java 2014-01-24 23:39:36 UTC (rev 7828) +++ branches/RDR/bigdata-rdf/src/java/com/bigdata/rdf/rio/ntriples/BigdataNTriplesParser.java 2014-01-26 20:37:25 UTC (rev 7829) @@ -421,31 +421,35 @@ // Create statement. BigdataStatement st = (BigdataStatement) createStatement( state.subject, state.predicate, state.object); - // Resolve against LRU map to blank node for statement. - BigdataBNode sid = sids.get(st); - if (sid != null) { - state.lastSID = sid; - } else { - /* - * Not found. - * - * TODO The use of the sid bnode in the context position should - * go away when we migrate to sids support in both triples and - * quads mode. - */ - // New blank node for "sid" of this statement. - state.lastSID = sid = (BigdataBNode) createBNode(); - // New statement using that "sid" as its context position. - st = getValueFactory().createStatement(state.subject, - state.predicate, state.object, sid); - // cache it. - sids.put(st,sid); - // mark this blank node as a "sid". - // st.setStatementIdentifier(true); - ((BigdataBNodeImpl) sid).setStatement(st); - // new statement so pass to the call back interface. - rdfHandler.handleStatement(st); - } + + state.lastSID = ((BigdataValueFactory) valueFactory).createBNode(st); + +// // Resolve against LRU map to blank node for statement. +// BigdataBNode sid = sids.get(st); +// if (sid != null) { +// state.lastSID = sid; +// } else { +// /* +// * Not found. +// * +// * TODO The use of the sid bnode in the context position should +// * go away when we migrate to sids support in both triples and +// * quads mode. +// */ +// // New blank node for "sid" of this statement. +// state.lastSID = sid = (BigdataBNode) createBNode(); +// // New statement using that "sid" as its context position. +// st = getValueFactory().createStatement(state.subject, +// state.predicate, state.object, sid); +// // cache it. +// sids.put(st,sid); +// // mark this blank node as a "sid". +// // st.setStatementIdentifier(true); +// ((BigdataBNodeImpl) sid).setStatement(st); +// // new statement so pass to the call back interface. +// rdfHandler.handleStatement(st); +// } + ... [truncated message content] |