From: <mrp...@us...> - 2011-02-24 17:34:48
|
Revision: 4244 http://bigdata.svn.sourceforge.net/bigdata/?rev=4244&view=rev Author: mrpersonick Date: 2011-02-24 17:34:41 +0000 (Thu, 24 Feb 2011) Log Message: ----------- added a few more VE bops Modified Paths: -------------- branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/constraints/IsLiteralBOp.java branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/BigdataEvaluationStrategyImpl3.java Added Paths: ----------- branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/constraints/IsBNodeBOp.java branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/constraints/IsURIBOp.java branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/constraints/StrBOp.java Added: branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/constraints/IsBNodeBOp.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/constraints/IsBNodeBOp.java (rev 0) +++ branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/constraints/IsBNodeBOp.java 2011-02-24 17:34:41 UTC (rev 4244) @@ -0,0 +1,91 @@ +/* + +Copyright (C) SYSTAP, LLC 2006-2007. 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.constraints; + +import java.util.Map; + +import com.bigdata.bop.BOp; +import com.bigdata.bop.IBindingSet; +import com.bigdata.bop.IValueExpression; +import com.bigdata.bop.IVariable; +import com.bigdata.rdf.error.SparqlTypeErrorException; +import com.bigdata.rdf.internal.IV; +import com.bigdata.rdf.internal.XSDBooleanIV; + +/** + * Imposes the constraint <code>isBNode(x)</code>. + */ +public class IsBNodeBOp extends ValueExpressionBOp + implements IValueExpression<IV> { + + /** + * + */ + private static final long serialVersionUID = 3125106876006900339L; + + public IsBNodeBOp(final IVariable<IV> x) { + + this(new BOp[] { x }, null/*annocations*/); + + } + + /** + * Required shallow copy constructor. + */ + public IsBNodeBOp(final BOp[] args, final Map<String, Object> anns) { + + super(args, anns); + + if (args.length != 1 || args[0] == null) + throw new IllegalArgumentException(); + + } + + /** + * Required deep copy constructor. + */ + public IsBNodeBOp(final IsBNodeBOp op) { + super(op); + } + + public boolean accept(final IBindingSet bs) { + + final IV iv = get(0).get(bs); + + // not yet bound + if (iv == null) + throw new SparqlTypeErrorException(); + + return iv.isBNode(); + + } + + public IV get(final IBindingSet bs) { + + return accept(bs) ? XSDBooleanIV.TRUE : XSDBooleanIV.FALSE; + + } + +} Modified: branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/constraints/IsLiteralBOp.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/constraints/IsLiteralBOp.java 2011-02-24 17:34:11 UTC (rev 4243) +++ branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/constraints/IsLiteralBOp.java 2011-02-24 17:34:41 UTC (rev 4244) @@ -70,7 +70,7 @@ super(op); } - public boolean accept(IBindingSet bs) { + public boolean accept(final IBindingSet bs) { final IV iv = get(0).get(bs); Added: branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/constraints/IsURIBOp.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/constraints/IsURIBOp.java (rev 0) +++ branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/constraints/IsURIBOp.java 2011-02-24 17:34:41 UTC (rev 4244) @@ -0,0 +1,91 @@ +/* + +Copyright (C) SYSTAP, LLC 2006-2007. 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.constraints; + +import java.util.Map; + +import com.bigdata.bop.BOp; +import com.bigdata.bop.IBindingSet; +import com.bigdata.bop.IValueExpression; +import com.bigdata.bop.IVariable; +import com.bigdata.rdf.error.SparqlTypeErrorException; +import com.bigdata.rdf.internal.IV; +import com.bigdata.rdf.internal.XSDBooleanIV; + +/** + * Imposes the constraint <code>isURI(x)</code>. + */ +public class IsURIBOp extends ValueExpressionBOp + implements IValueExpression<IV> { + + /** + * + */ + private static final long serialVersionUID = 3125106876006900339L; + + public IsURIBOp(final IVariable<IV> x) { + + this(new BOp[] { x }, null/*annocations*/); + + } + + /** + * Required shallow copy constructor. + */ + public IsURIBOp(final BOp[] args, final Map<String, Object> anns) { + + super(args, anns); + + if (args.length != 1 || args[0] == null) + throw new IllegalArgumentException(); + + } + + /** + * Required deep copy constructor. + */ + public IsURIBOp(final IsURIBOp op) { + super(op); + } + + public boolean accept(final IBindingSet bs) { + + final IV iv = get(0).get(bs); + + // not yet bound + if (iv == null) + throw new SparqlTypeErrorException(); + + return iv.isURI(); + + } + + public IV get(final IBindingSet bs) { + + return accept(bs) ? XSDBooleanIV.TRUE : XSDBooleanIV.FALSE; + + } + +} Added: branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/constraints/StrBOp.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/constraints/StrBOp.java (rev 0) +++ branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/constraints/StrBOp.java 2011-02-24 17:34:41 UTC (rev 4244) @@ -0,0 +1,118 @@ +/* + +Copyright (C) SYSTAP, LLC 2006-2007. 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.constraints; + +import java.util.Map; + +import org.openrdf.model.URI; + +import com.bigdata.bop.BOp; +import com.bigdata.bop.IBindingSet; +import com.bigdata.bop.IValueExpression; +import com.bigdata.bop.IVariable; +import com.bigdata.rdf.error.SparqlTypeErrorException; +import com.bigdata.rdf.internal.IV; +import com.bigdata.rdf.internal.StrIV; +import com.bigdata.rdf.lexicon.LexiconRelation; +import com.bigdata.rdf.model.BigdataLiteral; +import com.bigdata.rdf.model.BigdataValueFactory; +import com.bigdata.rdf.store.AbstractTripleStore; + +/** + * Imposes the constraint <code>isURI(x)</code>. + */ +public class StrBOp extends ValueExpressionBOp + implements IValueExpression<IV> { + + /** + * + */ + private static final long serialVersionUID = 3125106876006900339L; + + public StrBOp(final IVariable<IV> x) { + + this(new BOp[] { x }, null/*annocations*/); + + } + + /** + * Required shallow copy constructor. + */ + public StrBOp(final BOp[] args, final Map<String, Object> anns) { + + super(args, anns); + + if (args.length != 1 || args[0] == null) + throw new IllegalArgumentException(); + + } + + /** + * Required deep copy constructor. + */ + public StrBOp(final StrBOp op) { + super(op); + } + + public IV get(final IBindingSet bs) { + + final IV iv = get(0).get(bs); + + // not yet bound + if (iv == null) + throw new SparqlTypeErrorException(); + + // uh oh how the heck do I get my hands on this? big change + final AbstractTripleStore db = null; + + // use to materialize my terms + final LexiconRelation lex = db.getLexiconRelation(); + + // use to create my simple literals + final BigdataValueFactory vf = db.getValueFactory(); + + if (iv.isURI()) { + // return new simple literal using URI label + final URI uri = (URI) iv.asValue(lex); + final BigdataLiteral str = vf.createLiteral(uri.toString()); + return new StrIV(iv, str); + } else if (iv.isLiteral()) { + final BigdataLiteral lit = (BigdataLiteral) iv.asValue(lex); + if (lit.getDatatype() == null && lit.getLanguage() == null) { + // if simple literal return it + return iv; + } + else { + // else return new simple literal using Literal.getLabel + final BigdataLiteral str = vf.createLiteral(lit.getLabel()); + return new StrIV(iv, str); + } + } else { + throw new SparqlTypeErrorException(); + } + + } + +} Modified: branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/BigdataEvaluationStrategyImpl3.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/BigdataEvaluationStrategyImpl3.java 2011-02-24 17:34:11 UTC (rev 4243) +++ branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/BigdataEvaluationStrategyImpl3.java 2011-02-24 17:34:41 UTC (rev 4244) @@ -30,7 +30,10 @@ import org.openrdf.query.algebra.Compare; import org.openrdf.query.algebra.Filter; import org.openrdf.query.algebra.Group; +import org.openrdf.query.algebra.IsBNode; import org.openrdf.query.algebra.IsLiteral; +import org.openrdf.query.algebra.IsResource; +import org.openrdf.query.algebra.IsURI; import org.openrdf.query.algebra.Join; import org.openrdf.query.algebra.LeftJoin; import org.openrdf.query.algebra.MathExpr; @@ -48,6 +51,7 @@ import org.openrdf.query.algebra.SameTerm; import org.openrdf.query.algebra.StatementPattern; import org.openrdf.query.algebra.StatementPattern.Scope; +import org.openrdf.query.algebra.Str; import org.openrdf.query.algebra.TupleExpr; import org.openrdf.query.algebra.UnaryTupleOperator; import org.openrdf.query.algebra.Union; @@ -72,6 +76,7 @@ import com.bigdata.bop.NV; import com.bigdata.bop.PipelineOp; import com.bigdata.bop.ap.Predicate; +import com.bigdata.bop.constraint.INBinarySearch; import com.bigdata.bop.engine.IRunningQuery; import com.bigdata.bop.engine.QueryEngine; import com.bigdata.bop.solutions.ISortOrder; @@ -82,14 +87,16 @@ import com.bigdata.rdf.internal.XSDBooleanIV; import com.bigdata.rdf.internal.constraints.AndBOp; import com.bigdata.rdf.internal.constraints.CompareBOp; +import com.bigdata.rdf.internal.constraints.Constraint; import com.bigdata.rdf.internal.constraints.EBVBOp; +import com.bigdata.rdf.internal.constraints.IsBNodeBOp; import com.bigdata.rdf.internal.constraints.IsBoundBOp; import com.bigdata.rdf.internal.constraints.IsLiteralBOp; +import com.bigdata.rdf.internal.constraints.IsURIBOp; import com.bigdata.rdf.internal.constraints.MathBOp; import com.bigdata.rdf.internal.constraints.NotBOp; import com.bigdata.rdf.internal.constraints.OrBOp; import com.bigdata.rdf.internal.constraints.SameTermBOp; -import com.bigdata.rdf.internal.constraints.Constraint; import com.bigdata.rdf.lexicon.LexiconRelation; import com.bigdata.rdf.model.BigdataValue; import com.bigdata.rdf.sail.BigdataSail.Options; @@ -2066,6 +2073,12 @@ return toVE((Bound) ve); } else if (ve instanceof IsLiteral) { return toVE((IsLiteral) ve); + } else if (ve instanceof IsBNode) { + return toVE((IsBNode) ve); + } else if (ve instanceof IsResource) { + return toVE((IsResource) ve); + } else if (ve instanceof IsURI) { + return toVE((IsURI) ve); } throw new UnsupportedOperatorException(ve); @@ -2152,6 +2165,22 @@ return new IsLiteralBOp(var); } + private IValueExpression<IV> toVE(final IsBNode isBNode) { + final IVariable<IV> var = (IVariable<IV>) toVE(isBNode.getArg()); + return new IsBNodeBOp(var); + } + + private IValueExpression<IV> toVE(final IsResource isResource) { + final IVariable<IV> var = (IVariable<IV>) toVE(isResource.getArg()); + // isResource == isURI || isBNode == !isLiteral + return new NotBOp(new IsLiteralBOp(var)); + } + + private IValueExpression<IV> toVE(final IsURI isURI) { + final IVariable<IV> var = (IVariable<IV>) toVE(isURI.getArg()); + return new IsURIBOp(var); + } + /** * Generate a bigdata term from a Sesame term. * <p> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |