|
From: <mrp...@us...> - 2010-07-26 19:14:46
|
Revision: 3298
http://bigdata.svn.sourceforge.net/bigdata/?rev=3298&view=rev
Author: mrpersonick
Date: 2010-07-26 19:14:39 +0000 (Mon, 26 Jul 2010)
Log Message:
-----------
fixing bnodes, moving extensions to samples
Modified Paths:
--------------
branches/LEXICON_REFACTOR_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/model/BigdataValueFactoryImpl.java
branches/LEXICON_REFACTOR_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/store/AbstractTripleStore.java
branches/LEXICON_REFACTOR_BRANCH/bigdata-rdf/src/test/com/bigdata/rdf/lexicon/TestInlining.java
branches/LEXICON_REFACTOR_BRANCH/bigdata-rdf/src/test/com/bigdata/rdf/store/TestTripleStore.java
Added Paths:
-----------
branches/LEXICON_REFACTOR_BRANCH/bigdata-rdf/src/samples/
branches/LEXICON_REFACTOR_BRANCH/bigdata-rdf/src/samples/com/
branches/LEXICON_REFACTOR_BRANCH/bigdata-rdf/src/samples/com/bigdata/
branches/LEXICON_REFACTOR_BRANCH/bigdata-rdf/src/samples/com/bigdata/rdf/
branches/LEXICON_REFACTOR_BRANCH/bigdata-rdf/src/samples/com/bigdata/rdf/internal/
branches/LEXICON_REFACTOR_BRANCH/bigdata-rdf/src/samples/com/bigdata/rdf/internal/ColorsEnumExtension.java
branches/LEXICON_REFACTOR_BRANCH/bigdata-rdf/src/samples/com/bigdata/rdf/internal/EpochExtension.java
branches/LEXICON_REFACTOR_BRANCH/bigdata-rdf/src/samples/com/bigdata/rdf/internal/SampleExtensionFactory.java
Modified: branches/LEXICON_REFACTOR_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/model/BigdataValueFactoryImpl.java
===================================================================
--- branches/LEXICON_REFACTOR_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/model/BigdataValueFactoryImpl.java 2010-07-26 19:13:50 UTC (rev 3297)
+++ branches/LEXICON_REFACTOR_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/model/BigdataValueFactoryImpl.java 2010-07-26 19:14:39 UTC (rev 3298)
@@ -173,7 +173,7 @@
*/
protected String nextID() {
- return "_"+UUID.randomUUID();
+ return "u"+UUID.randomUUID();
}
Modified: branches/LEXICON_REFACTOR_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/store/AbstractTripleStore.java
===================================================================
--- branches/LEXICON_REFACTOR_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/store/AbstractTripleStore.java 2010-07-26 19:13:50 UTC (rev 3297)
+++ branches/LEXICON_REFACTOR_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/store/AbstractTripleStore.java 2010-07-26 19:14:39 UTC (rev 3298)
@@ -44,7 +44,6 @@
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.atomic.AtomicLong;
-
import org.apache.log4j.Logger;
import org.openrdf.model.Literal;
import org.openrdf.model.Resource;
@@ -56,7 +55,6 @@
import org.openrdf.model.vocabulary.RDFS;
import org.openrdf.model.vocabulary.XMLSchema;
import org.openrdf.rio.rdfxml.RDFXMLParser;
-
import com.bigdata.btree.AbstractBTree;
import com.bigdata.btree.BTree;
import com.bigdata.btree.BytesUtil;
@@ -80,6 +78,8 @@
import com.bigdata.rdf.inf.JustificationIterator;
import com.bigdata.rdf.internal.DefaultExtensionFactory;
import com.bigdata.rdf.internal.IDatatypeURIResolver;
+import com.bigdata.rdf.internal.IExtension;
+import com.bigdata.rdf.internal.IExtensionFactory;
import com.bigdata.rdf.internal.IV;
import com.bigdata.rdf.lexicon.BigdataRDFFullTextIndex;
import com.bigdata.rdf.lexicon.ITermIdCodes;
Copied: branches/LEXICON_REFACTOR_BRANCH/bigdata-rdf/src/samples/com/bigdata/rdf/internal/ColorsEnumExtension.java (from rev 3289, branches/LEXICON_REFACTOR_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/ColorsEnumExtension.java)
===================================================================
--- branches/LEXICON_REFACTOR_BRANCH/bigdata-rdf/src/samples/com/bigdata/rdf/internal/ColorsEnumExtension.java (rev 0)
+++ branches/LEXICON_REFACTOR_BRANCH/bigdata-rdf/src/samples/com/bigdata/rdf/internal/ColorsEnumExtension.java 2010-07-26 19:14:39 UTC (rev 3298)
@@ -0,0 +1,169 @@
+/**
+
+Copyright (C) SYSTAP, LLC 2006-2010. 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;
+
+import org.openrdf.model.Literal;
+import org.openrdf.model.URI;
+import org.openrdf.model.Value;
+import org.openrdf.model.impl.URIImpl;
+import com.bigdata.rdf.model.BigdataURI;
+import com.bigdata.rdf.model.BigdataValue;
+import com.bigdata.rdf.model.BigdataValueFactory;
+import com.bigdata.rdf.store.BD;
+
+/**
+ * Example of how to do a custom enum and map that enum over a byte using a
+ * native inline {@link XSDByteIV}.
+ */
+public class ColorsEnumExtension<V extends BigdataValue> implements IExtension<V> {
+
+ /**
+ * The datatype URI for the colors enum extension.
+ */
+ public transient static final URI COLOR = new URIImpl(BD.NAMESPACE + "Color");
+
+ private BigdataURI color;
+
+ public ColorsEnumExtension() {
+
+ }
+
+ public void resolveDatatype(final IDatatypeURIResolver resolver) {
+
+ this.color = resolver.resolve(COLOR);
+
+ }
+
+ public BigdataURI getDatatype() {
+
+ return color;
+
+ }
+
+ /**
+ * Attempts to convert the supplied RDF value into a colors enum
+ * representation. Tests for a literal value with the correct datatype
+ * that can be converted to one of the colors in the {@link Color} enum
+ * based on the string value of the literal's label. Each {@link Color}
+ * in the enum maps to a particular byte. This byte is encoded in a
+ * delegate {@link XSDByteIV}, and an {@link ExtensionIV} is returned that
+ * wraps the native type.
+ */
+ public ExtensionIV createIV(final Value value) {
+
+ if (value instanceof Literal == false)
+ throw new IllegalArgumentException();
+
+ final Literal l = (Literal) value;
+
+ if (l.getDatatype() == null || !color.equals(l.getDatatype()))
+ throw new IllegalArgumentException();
+
+ final String s = value.stringValue();
+
+ final Color c = Enum.valueOf(Color.class, s);
+
+ // not a valid color
+ if (c == null)
+ return null;
+
+ final AbstractLiteralIV delegate = new XSDByteIV(c.getByte());
+
+ return new ExtensionIV(delegate, (TermId) getDatatype().getIV());
+
+ }
+
+ /**
+ * Attempt to convert the {@link AbstractLiteralIV#byteValue()} back into
+ * a {@link Color}, and then use the string value of the {@link Color} to
+ * create an RDF literal.
+ */
+ public V asValue(final ExtensionIV iv, final BigdataValueFactory vf) {
+
+ final byte b = iv.getDelegate().byteValue();
+
+ final Color c = Color.valueOf(b);
+
+ if (c == null)
+ throw new RuntimeException("bad color got encoded somehow");
+
+ return (V) vf.createLiteral(c.toString(), color);
+
+ }
+
+ /**
+ * Simple demonstration enum for some common colors. Can fit up to 256 enum
+ * values into an enum projected onto a byte.
+ */
+ public enum Color {
+
+ Red((byte) 0),
+ Blue((byte) 1),
+ Green((byte) 2),
+ Yellow((byte) 3),
+ Orange((byte) 4),
+ Purple((byte) 5),
+ Black((byte) 6),
+ White((byte) 7),
+ Brown((byte) 8);
+
+ private Color(final byte b) {
+ this.b = b;
+ }
+
+ static final public Color valueOf(final byte b) {
+ switch (b) {
+ case 0:
+ return Red;
+ case 1:
+ return Blue;
+ case 2:
+ return Green;
+ case 3:
+ return Yellow;
+ case 4:
+ return Orange;
+ case 5:
+ return Purple;
+ case 6:
+ return Black;
+ case 7:
+ return White;
+ case 8:
+ return Brown;
+ default:
+ throw new IllegalArgumentException(Byte.toString(b));
+ }
+ }
+
+ private final byte b;
+
+ public byte getByte() {
+ return b;
+ }
+
+ }
+
+}
Copied: branches/LEXICON_REFACTOR_BRANCH/bigdata-rdf/src/samples/com/bigdata/rdf/internal/EpochExtension.java (from rev 3289, branches/LEXICON_REFACTOR_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/EpochExtension.java)
===================================================================
--- branches/LEXICON_REFACTOR_BRANCH/bigdata-rdf/src/samples/com/bigdata/rdf/internal/EpochExtension.java (rev 0)
+++ branches/LEXICON_REFACTOR_BRANCH/bigdata-rdf/src/samples/com/bigdata/rdf/internal/EpochExtension.java 2010-07-26 19:14:39 UTC (rev 3298)
@@ -0,0 +1,110 @@
+/**
+
+Copyright (C) SYSTAP, LLC 2006-2010. 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;
+
+import org.openrdf.model.Literal;
+import org.openrdf.model.URI;
+import org.openrdf.model.Value;
+import org.openrdf.model.datatypes.XMLDatatypeUtil;
+import org.openrdf.model.impl.URIImpl;
+import com.bigdata.rdf.model.BigdataURI;
+import com.bigdata.rdf.model.BigdataValue;
+import com.bigdata.rdf.model.BigdataValueFactory;
+import com.bigdata.rdf.store.BD;
+
+/**
+ * This implementation of {@link IExtension} implements inlining for literals
+ * that represent time in milliseconds since the epoch. The milliseconds are
+ * encoded as an inline long.
+ */
+public class EpochExtension<V extends BigdataValue> implements IExtension<V> {
+
+ /**
+ * The datatype URI for the epoch extension.
+ */
+ public transient static final URI EPOCH = new URIImpl(BD.NAMESPACE + "Epoch");
+
+ private BigdataURI epoch;
+
+ public EpochExtension() {
+ }
+
+ public void resolveDatatype(final IDatatypeURIResolver resolver) {
+
+ this.epoch = resolver.resolve(EPOCH);
+
+ }
+
+ public BigdataURI getDatatype() {
+
+ return epoch;
+
+ }
+
+ /**
+ * Attempts to convert the supplied value into an epoch representation.
+ * Tests for a literal value with the correct datatype that can be converted
+ * to a positive long integer. Encodes the long in a delegate
+ * {@link XSDLongIV}, and returns an {@link ExtensionIV} to wrap the native
+ * type.
+ */
+ public ExtensionIV createIV(final Value value) {
+
+ if (value instanceof Literal == false)
+ throw new IllegalArgumentException();
+
+ final Literal lit = (Literal) value;
+
+ final URI dt = lit.getDatatype();
+
+ if (dt == null || !EPOCH.stringValue().equals(dt.stringValue()))
+ throw new IllegalArgumentException();
+
+ final String s = value.stringValue();
+
+ final long l = XMLDatatypeUtil.parseLong(s);
+
+ // can't have negative epoch values
+ if (l < 0)
+ return null;
+
+ final AbstractLiteralIV delegate = new XSDLongIV(l);
+
+ return new ExtensionIV(delegate, (TermId) getDatatype().getIV());
+
+ }
+
+ /**
+ * Use the string value of the {@link ExtensionIV} (which defers to the
+ * string value of the native type) to create a literal with the epoch
+ * datatype.
+ */
+ public V asValue(final ExtensionIV iv, final BigdataValueFactory vf) {
+
+ return (V) vf.createLiteral(iv.stringValue(), epoch);
+
+ }
+
+}
Added: branches/LEXICON_REFACTOR_BRANCH/bigdata-rdf/src/samples/com/bigdata/rdf/internal/SampleExtensionFactory.java
===================================================================
--- branches/LEXICON_REFACTOR_BRANCH/bigdata-rdf/src/samples/com/bigdata/rdf/internal/SampleExtensionFactory.java (rev 0)
+++ branches/LEXICON_REFACTOR_BRANCH/bigdata-rdf/src/samples/com/bigdata/rdf/internal/SampleExtensionFactory.java 2010-07-26 19:14:39 UTC (rev 3298)
@@ -0,0 +1,35 @@
+package com.bigdata.rdf.internal;
+
+/**
+ * Simple {@link IExtensionFactory} implementation that creates two
+ * {@link IExtension}s - the {@link EpochExtension} and the
+ * {@link ColorsEnumExtension}.
+ */
+public class SampleExtensionFactory implements IExtensionFactory {
+
+ private final IExtension[] extensions;
+
+ public SampleExtensionFactory() {
+
+ extensions = new IExtension[] {
+ new EpochExtension(),
+ new ColorsEnumExtension()
+ };
+
+ }
+
+ public void resolveDatatypes(final IDatatypeURIResolver resolver) {
+
+ for (IExtension extension : extensions) {
+ extension.resolveDatatype(resolver);
+ }
+
+ }
+
+ public IExtension[] getExtensions() {
+
+ return extensions;
+
+ }
+
+}
Modified: branches/LEXICON_REFACTOR_BRANCH/bigdata-rdf/src/test/com/bigdata/rdf/lexicon/TestInlining.java
===================================================================
--- branches/LEXICON_REFACTOR_BRANCH/bigdata-rdf/src/test/com/bigdata/rdf/lexicon/TestInlining.java 2010-07-26 19:13:50 UTC (rev 3297)
+++ branches/LEXICON_REFACTOR_BRANCH/bigdata-rdf/src/test/com/bigdata/rdf/lexicon/TestInlining.java 2010-07-26 19:14:39 UTC (rev 3298)
@@ -38,6 +38,7 @@
import com.bigdata.rdf.internal.EpochExtension;
import com.bigdata.rdf.internal.ExtensionIV;
import com.bigdata.rdf.internal.IV;
+import com.bigdata.rdf.internal.SampleExtensionFactory;
import com.bigdata.rdf.internal.XSD;
import com.bigdata.rdf.model.BigdataBNode;
import com.bigdata.rdf.model.BigdataLiteral;
@@ -195,17 +196,19 @@
// lookup/add some values.
final BigdataValueFactory f = store.getValueFactory();
- final BigdataBNode b1 = f.createBNode("1");
- final BigdataBNode b01 = f.createBNode("01");
- final BigdataBNode b2 = f.createBNode(UUID.randomUUID().toString());
+ final BigdataBNode b1 = f.createBNode("i1");
+ final BigdataBNode b01 = f.createBNode("i01");
+ final BigdataBNode b2 = f.createBNode("u"+UUID.randomUUID().toString());
final BigdataBNode b3 = f.createBNode("foo");
final BigdataBNode b4 = f.createBNode("foo12345");
+ final BigdataBNode b5 = f.createBNode("12345");
terms.add(b1);
terms.add(b01);
terms.add(b2);
terms.add(b3);
terms.add(b4);
+ terms.add(b5);
final Map<IV, BigdataValue> ids = doAddTermsTest(store, terms);
@@ -214,6 +217,7 @@
assertTrue(b2.getIV().isInline());
assertFalse(b3.getIV().isInline());
assertFalse(b4.getIV().isInline());
+ assertFalse(b5.getIV().isInline());
if (store.isStable()) {
@@ -261,6 +265,10 @@
// test w/o the full text index.
properties.setProperty(Options.TEXT_INDEX, "false");
+ // test with the sample extension factory
+ properties.setProperty(Options.EXTENSION_FACTORY_CLASS,
+ SampleExtensionFactory.class.getName());
+
AbstractTripleStore store = getStore(properties);
try {
@@ -349,6 +357,10 @@
// test w/o the full text index.
properties.setProperty(Options.TEXT_INDEX, "false");
+ // test with the sample extension factory
+ properties.setProperty(Options.EXTENSION_FACTORY_CLASS,
+ SampleExtensionFactory.class.getName());
+
AbstractTripleStore store = getStore(properties);
try {
Modified: branches/LEXICON_REFACTOR_BRANCH/bigdata-rdf/src/test/com/bigdata/rdf/store/TestTripleStore.java
===================================================================
--- branches/LEXICON_REFACTOR_BRANCH/bigdata-rdf/src/test/com/bigdata/rdf/store/TestTripleStore.java 2010-07-26 19:13:50 UTC (rev 3297)
+++ branches/LEXICON_REFACTOR_BRANCH/bigdata-rdf/src/test/com/bigdata/rdf/store/TestTripleStore.java 2010-07-26 19:14:39 UTC (rev 3298)
@@ -586,9 +586,12 @@
final IV bn1_id = store.addTerm(bn1);
assertTrue(bn1_id != NULL);
+ System.err.println(bn1_id);
final IV bn2_id = store.addTerm(bn2);
assertTrue(bn2_id != NULL);
-
+ System.err.println(bn2_id);
+ System.err.println(storeBlankNodes);
+
assertEquals("#terms", 8 + 3 + (store.getLexiconRelation()
.isStoreBlankNodes() ? 2 : 0), store.getTermCount());
assertEquals("#uris", 8, store.getURICount());
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|