/* * (c) Copyright 2008 Hewlett-Packard Development Company, LP * All rights reserved. * [See end of file] */ package dev; import org.jrdf.graph.Node; import org.jrdf.graph.ObjectNode; import org.jrdf.graph.PredicateNode; import org.jrdf.graph.SubjectNode; import org.mulgara.itql.ItqlInterpreterBean; import org.mulgara.query.Answer; import org.mulgara.query.ConstraintExpression; import org.mulgara.query.Query; import org.mulgara.query.Variable; import org.mulgara.query.rdf.BlankNodeImpl; import org.mulgara.server.Session; import com.hp.hpl.jena.mulgara.JenaMulgara; public class Dev { public static void main(String ...args) throws Exception { String server = "rmi://localhost/server1" ; String graphURI = server+"#model1" ; Session session = JenaMulgara.createSession(server) ; ItqlInterpreterBean interpreter = new ItqlInterpreterBean() ; String qs = "select $s $p from where $s $p 'M_BLANK'" ; Query query = interpreter.buildQuery(qs) ; Answer answer = session.query(query) ; answer.beforeFirst() ; System.out.printf("Count = %d\n", answer.getRowCount()) ; Node b = null ; while(answer.next()) { Node s = (SubjectNode)answer.getObject("s") ; b = s ; Node p = (PredicateNode)answer.getObject("p") ; System.out.printf("s = %s\n", s) ; //Node o = (ObjectNode)answer.getObject("o") ; //System.out.printf("%s %s %s\n", s, p, o) ; } System.out.printf("End answer\n") ; Variable v = new Variable("s") ; Query query2 = interpreter.buildQuery("select $s $p $o from where $s $p $o" ) ; ConstraintExpression e = new org.mulgara.query.ConstraintIs(v, (BlankNodeImpl)b); e = new org.mulgara.query.ConstraintConjunction(query2.getConstraintExpression(), e) ; query2 = new Query(query2, e) ; answer = session.query(query2) ; answer.beforeFirst() ; System.out.printf("Count = %d\n", answer.getRowCount()) ; while(answer.next()) { Node s = (SubjectNode)answer.getObject("s") ; Node p = (PredicateNode)answer.getObject("p") ; Node o = (ObjectNode)answer.getObject("o") ; System.out.printf("%s %s %s\n", s, p, o) ; } System.out.printf("End answer\n") ; } } /* * (c) Copyright 2008 Hewlett-Packard Development Company, LP * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. The name of the author may not be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */