Java Code Examples for com.hp.hpl.jena.graph.Node

The following are top voted examples for showing how to use com.hp.hpl.jena.graph.Node. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: S2X   File: SparkBGP.java   Source Code and License 6 votes vote down vote up
private void buildBGP(OpBGP op) {
final List<Triple> triples = op.getPattern().getList();
for (final Triple triple : triples) {
    final Node subjectNode = triple.getSubject();
    final Node predicateNode = triple.getPredicate();
    final Node objectNode = triple.getObject();

    final String subject = PrefixUtil.collapsePrefix(FmtUtils
	    .stringForNode(subjectNode, prefixes));
    final String object = PrefixUtil.collapsePrefix(FmtUtils
	    .stringForNode(objectNode, prefixes));
    final String predicate = PrefixUtil.collapsePrefix(FmtUtils
	    .stringForNode(predicateNode, prefixes));

    if (bgp == null) {
	bgp = new ArrayList<TriplePattern>();
    }
    bgp.add(new TriplePattern(subject, predicate, object));
}
   }
 
Example 2
Project: S2X   File: Add.java   Source Code and License 6 votes vote down vote up
@Override
   public String getValue(SolutionMapping solution) {
String left = "";
String right = "";
if (expr1 instanceof ExprVar) {
    left = solution.getValueToField(((ExprVar) expr1).getVar());
} else {
    left = ((IValueType) expr1).getValue(solution);
}

if (expr2 instanceof ExprVar) {
    right = solution.getValueToField(((ExprVar) expr2).getVar());
} else {
    right = ((IValueType) expr2).getValue(solution);
}

Node nodeLeft = NodeFactoryExtra.parseNode(left);
Node nodeRight = NodeFactoryExtra.parseNode(right);
Integer leftInt = (Integer) nodeLeft.getLiteral().getValue();
Integer rightInt = (Integer) nodeRight.getLiteral().getValue();

int res = leftInt + rightInt;

return String.format(
	"\"%s\"^^<http://www.w3.org/2001/XMLSchema#integer>", res);
   }
 
Example 3
Project: S2X   File: Subtract.java   Source Code and License 6 votes vote down vote up
@Override
   public String getValue(SolutionMapping solution) {
String left = "";
String right = "";
if (expr1 instanceof ExprVar) {
    left = solution.getValueToField(((ExprVar) expr1).getVar());
} else {
    left = ((IValueType) expr1).getValue(solution);
}

if (expr2 instanceof ExprVar) {
    right = solution.getValueToField(((ExprVar) expr2).getVar());
} else {
    right = ((IValueType) expr2).getValue(solution);
}

Node nodeLeft = NodeFactoryExtra.parseNode(left);
Node nodeRight = NodeFactoryExtra.parseNode(right);
Integer leftInt = (Integer) nodeLeft.getLiteral().getValue();
Integer rightInt = (Integer) nodeRight.getLiteral().getValue();

int res = leftInt - rightInt;

return String.format(
	"\"%s\"^^<http://www.w3.org/2001/XMLSchema#integer>", res);
   }
 
Example 4
Project: S2RDF   File: AlgebraTransformer.java   Source Code and License 6 votes vote down vote up
/**
 * Visitor for the property path
 * @author Simon Skilevic
 */
@Override
public void visit(OpPath opPath) {
	// Path subject
	Node subject = opPath.getTriplePath().getSubject();
	// Path object
	Node object = opPath.getTriplePath().getObject();
	// Property path 
	Path tPath = opPath.getTriplePath().getPath();
	
	String stringPath = tPath.toString();
	ArrayList<String> pathsStr = TransformerHelper.findAllPossiblePathes(stringPath);
	int id=0;
	for (String path:pathsStr){
		BasicPattern pt = TransformerHelper.transformPathToBasicPattern(subject, path, object);
		OpBGP opBGP = new OpBGP(pt);
    	stack.push(new SqlBGP(opBGP, prefixes));
		id++;
		if (id>1) {
			 SqlOp rightOp = stack.pop();
		     SqlOp leftOp = stack.pop();
		     stack.push(new SQLUnion(null, leftOp, rightOp, prefixes));
		}
	}
	
}
 
Example 5
Project: S2RDF   File: TripleGroup.java   Source Code and License 6 votes vote down vote up
private HashMap<String, String[]> getMappingVarsOfTriple(Triple t) {
	HashMap<String, String[]> result = new HashMap<String, String[]>();
	Node subject = t.getSubject();
	Node predicate = t.getPredicate();
	Node object = t.getObject();
	if (subject.isVariable())
		result.put(subject.getName(),
				new String[] { Tags.SUBJECT_COLUMN_NAME });
	if (predicate.isVariable()) {
		result.put(predicate.getName(),
				new String[] { Tags.PREDICATE_COLUMN_NAME });
	}
	if (object.isVariable()) {
		result.put(object.getName(),
				new String[] { Tags.OBJECT_COLUMN_NAME });
	}
	return result;
}
 
Example 6
Project: PigSPARQL   File: PigBGP.java   Source Code and License 6 votes vote down vote up
protected ArrayList<String> getSchemaOfTriple(Triple t) {
	ArrayList<String> schema = new ArrayList<String>();
	Node subject = t.getSubject();
	Node predicate = t.getPredicate();
	Node object = t.getObject();
	if (subject.isVariable())
		schema.add(subject.getName());
	else
		schema.add(Tags.NO_VAR);
	if (predicate.isVariable())
		schema.add(predicate.getName());
	else
		schema.add(Tags.NO_VAR);
	if (object.isVariable())
		schema.add(object.getName());
	else
		schema.add(Tags.NO_VAR);
	return schema;
}
 
Example 7
Project: Sempala   File: ImpalaBgpExtVPMultiTable.java   Source Code and License 6 votes vote down vote up
/**
 * Use defined prefixes for making predicates compatible with ExtVP table naming.
 * 
 * @param Predicate - Predicate to be renamed.
 * @return
 */
private String PrefixforExtVP(Node Predicate) {
	String URIPredicate = Predicate.toString();
	int index = URIPredicate.lastIndexOf('#');
	if (index == -1)
		index = URIPredicate.lastIndexOf('/');
	String URI = URIPredicate.substring(0, index + 1);
	String Pred = URIPredicate.substring(index + 1, URIPredicate.length());
	String Prefix = prefixes.getNsURIPrefix(URI);
	if (Prefix == null) {
		if (URI.contains("http"))
			return "_" + Pred + "_".replaceAll("[<>/.`~,\\s\\-:\\?]", "_");
		else {
			String RenamedURI = URI.replaceAll("[<>/.`~,\\s\\-:\\?]", "_");
			return RenamedURI + Pred;
		}
	} else
		return Prefix + "_" + Pred;
}
 
Example 8
Project: Sempala   File: SparkComplexTripleGroup.java   Source Code and License 6 votes vote down vote up
private HashMap<String, String[]> getMappingVarsOfTriple(Triple t) {
	HashMap<String, String[]> result = new HashMap<String, String[]>();
	Node subject = t.getSubject();
	Node predicate = t.getPredicate();
	Node object = t.getObject();
	if (subject.isVariable()) {
		result.put(subject.getName(), new String[] { Tags.SUBJECT_COLUMN_NAME });
	}
	if (predicate.isVariable()) {
		selectFromTripleStore = true;
		result.put(predicate.getName(), new String[] { Tags.PREDICATE_COLUMN_NAME });
	}
	if (object.isVariable()) {
		if (selectFromTripleStore) {
			result.put(object.getName(), new String[] { Tags.OBJECT_COLUMN_NAME });
		} else {
			String objectString = object.getName();
			String predicateString = getPropertyFromURI(FmtUtils
					.stringForNode(predicate, prefixMapping), false);
			result.put(objectString, new String[] { SpecialCharFilter.filter(predicateString) });
		}
	}
	return result;
}
 
Example 9
Project: Sempala   File: TripleGroup.java   Source Code and License 6 votes vote down vote up
private HashMap<String, String[]> getMappingVarsOfTriple(Triple t) {
	HashMap<String, String[]> result = new HashMap<String, String[]>();
	Node subject = t.getSubject();
	Node predicate = t.getPredicate();
	Node object = t.getObject();
	if (subject.isVariable())
		result.put(subject.getName(),
				new String[] { Tags.SUBJECT_COLUMN_NAME });
	if (predicate.isVariable()) {
		selectFromTripleStore = true;
		result.put(predicate.getName(),
				new String[] { Tags.PREDICATE_COLUMN_NAME });
	}
	if (object.isVariable()) {
		if (selectFromTripleStore) {
			result.put(object.getName(),
					new String[] { Tags.OBJECT_COLUMN_NAME });
		} else {
			result.put(object.getName(), new String[] { SpecialCharFilter
					.filter(FmtUtils
							.stringForNode(predicate, prefixMapping)) });
		}
	}
	return result;
}
 
Example 10
Project: BimSPARQL   File: FunctionBaseSpatialRelation.java   Source Code and License 6 votes vote down vote up
protected QueryIterator verify(Binding binding, Graph queryGraph, Node matchSubject, Node predicate,
		Node matchObject, ExecutionContext execCxt) {
	Geometry s=getGeometry(matchSubject, execCxt.getActiveGraph());
	Geometry o=getGeometry(matchObject, execCxt.getActiveGraph());
	try {
		if(evaluateSpatialRelation(s,o)){
			return IterLib.result(binding, execCxt);
		}
		else{
			return IterLib.noResults(execCxt);
		}
	} catch (GeometryException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}return IterLib.noResults(execCxt);
}
 
Example 11
Project: BimSPARQL   File: FunctionBaseProductEwktValue.java   Source Code and License 6 votes vote down vote up
@Override
protected QueryIterator verifyValue(Binding binding, Graph graph, Node product, Geometry geometry, Node object,
		ExecutionContext execCxt) {
	String obj;
	try{
	obj=(String)object.getLiteralValue();
	}catch (Exception e){
		return IterLib.noResults(execCxt);
	}
	String b=computeValue(geometry);
	if(b==null){
		return IterLib.noResults(execCxt);
	}
	if(b.equals(obj)){
		return IterLib.result(binding, execCxt);
	}
	return IterLib.noResults(execCxt);
}
 
Example 12
Project: BimSPARQL   File: FunctionBaseSpatialRelation.java   Source Code and License 6 votes vote down vote up
protected List<Node> getRelatedNodes(Node node, ExecutionContext execCxt) {
	Geometry geometry=getGeometry(node, execCxt.getActiveGraph());
	List<Node> nodes=new ArrayList<Node>();
	for (Node n:hashmap.keySet()){
		try {
			if(evaluateSpatialRelation(geometry, getGeometry(n,execCxt.getActiveGraph()))){
				nodes.add(n);
			}
		} catch (GeometryException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	nodes.remove(node);
	return nodes;   
}
 
Example 13
Project: r2rml-kit   File: PrettyPrinter.java   Source Code and License 6 votes vote down vote up
/**
 * Pretty-prints an RDF node and shortens URIs into QNames according to a
 * {@link PrefixMapping}.
 * @param n An RDF node
 * @return An N-Triples style textual representation with URIs shortened to QNames
 */
public static String toString(Node n, PrefixMapping prefixes) {
	if (n.isURI()) {
		return qNameOrURI(n.getURI(), prefixes);
	}
	if (n.isBlank()) {
		return "_:" + n.getBlankNodeLabel();
	}
	if (n.isVariable()) {
		return "?" + n.getName();
	}
	if (Node.ANY.equals(n)) {
		return "?ANY";
	}
	// Literal
	String s = "\"" + n.getLiteralLexicalForm() + "\"";
	if (!"".equals(n.getLiteralLanguage())) {
		s += "@" + n.getLiteralLanguage();
	}
	if (n.getLiteralDatatype() != null) {
		s += "^^" + qNameOrURI(n.getLiteralDatatypeURI(), prefixes);
	}
	return s;
}
 
Example 14
Project: c4a_data_repository   File: TransformExprToSQLApplyer.java   Source Code and License 6 votes vote down vote up
private void convertIsIRI(E_IsIRI expr)
{
	logger.debug("convertIsIRI " + expr.toString());
	
	expr.getArg().visit(this);
	
	Expression arg = expression.pop();
	
	if (arg instanceof AttributeExprEx) {
		AttributeExprEx variable = (AttributeExprEx) arg;
		NodeMaker nm = variable.getNodeMaker();
		DetermineNodeType filter = new DetermineNodeType();
		nm.describeSelf(filter);
		expression.push(filter.isLimittedToURIs() ? Expression.TRUE : Expression.FALSE);
	} else if (arg instanceof ConstantEx) {
		ConstantEx constant = (ConstantEx) arg;
		Node node = constant.getNode();
		expression.push(node.isURI() ? Expression.TRUE : Expression.FALSE);
	} else {
		conversionFailed(expr);
	}
}
 
Example 15
Project: c4a_data_repository   File: ExprTransformTest2.java   Source Code and License 6 votes vote down vote up
public void testDisjunction()
{
	List<Triple> pattern = new ArrayList<Triple>();
	pattern.add(Triple.create(Node.createVariable("s"), Node.createURI("http://example.org/value"), Node.createVariable("o")));
	NodeRelation[] rels = translate(pattern, "optimizer/filtertests.n3");
	
	NodeRelation intvalue = search("table2", "intvalue", rels);

	Expr disjunction = new E_LogicalOr(new E_Equals(new ExprVar("o"),  NodeValue.makeNode("1", XSDDatatype.XSDint)), new E_Equals(new ExprVar("o"), NodeValue.makeNode("2", XSDDatatype.XSDint)));
	
	Expression result = TransformExprToSQLApplyer.convert(disjunction, intvalue);
	TypedNodeMaker nm = (TypedNodeMaker) intvalue.nodeMaker(Var.alloc("o"));
	Expression e1 = nm.valueMaker().valueExpression("1");
	Expression e2 = nm.valueMaker().valueExpression("2");
	Expression expected = e1.or(e2);
	
	assertEquals("?o = \"1\"^^xsd:int || ?o = \"2\"^^xsd:int", expected, result);
}
 
Example 16
Project: r2rml-kit   File: PrettyPrinterTest.java   Source Code and License 6 votes vote down vote up
@Test
public void testNodePrettyPrinting() {
	assertEquals("\"foo\"", 
			PrettyPrinter.toString(Node.createLiteral("foo")));
	assertEquals("\"foo\"@en", 
			PrettyPrinter.toString(Node.createLiteral("foo", "en", null)));
	assertEquals("\"1\"^^xsd:int",
			PrettyPrinter.toString(Node.createLiteral("1", null, XSDDatatype.XSDint)));
	assertEquals("\"1\"^^xsd:int",
			PrettyPrinter.toString(Node.createLiteral("1", null, XSDDatatype.XSDint), PrefixMapping.Standard));
	assertEquals("_:foo", 
			PrettyPrinter.toString(Node.createAnon(new AnonId("foo"))));
	assertEquals("<http://example.org/>", 
			PrettyPrinter.toString(Node.createURI("http://example.org/")));
	assertEquals("<" + RDF.type.getURI() + ">", 
			PrettyPrinter.toString(RDF.type.asNode(), new PrefixMappingImpl()));
	assertEquals("rdf:type", 
			PrettyPrinter.toString(RDF.type.asNode(), PrefixMapping.Standard));
	assertEquals("?x", 
			PrettyPrinter.toString(Node.createVariable("x")));
	assertEquals("?ANY",
			PrettyPrinter.toString(Node.ANY));
}
 
Example 17
Project: BimSPARQL   File: GeometryConverter.java   Source Code and License 6 votes vote down vote up
public void addMaterialTriples(InstanceGeometry ig){
	if(ig.getColors()!=null&&ig.getColors().length>0){
    String materials=""+ig.getColors()[0];
    for(int i=1;i<ig.getColors().length;i++){
    	materials=materials+" "+ig.getColors()[i];
    }
    
    String indices=""+ig.getMaterialIndices()[0];
    for(int i=1;i<ig.getMaterialIndices().length;i++){
    	indices=indices+" "+ig.getMaterialIndices()[i];
    }
    
    Node hasMaterials=NodeFactory.createURI(GEOM.getURI()+"hasMaterials");
    Node hasMaterialIndices=NodeFactory.createURI(GEOM.getURI()+"hasMaterialIndices");
	getRdfWriter().triple(new Triple(NodeFactory.createURI(baseUri+"Geometry"+"_"+ig.getId()),hasMaterials,NodeFactory.createLiteral(materials)));
	getRdfWriter().triple(new Triple(NodeFactory.createURI(baseUri+"Geometry"+"_"+ig.getId()),hasMaterialIndices,NodeFactory.createLiteral((indices))));
	}
   
}
 
Example 18
Project: BimSPARQL   File: FunctionBaseSpatialRelation.java   Source Code and License 6 votes vote down vote up
protected HashMap<Node, Node> getNodeMap(ExecutionContext execCxt) {
	HashMap<Node,Node> nodeMap=new HashMap<Node,Node>();
	for (Node n:hashmap.keySet()){
		Geometry g1=getGeometry(n,execCxt.getActiveGraph());
		for(Node no:hashmap.keySet()){
			if(no!=n){
			Geometry g2=getGeometry(no,execCxt.getActiveGraph());
			try {
				if(evaluateSpatialRelation(g1, g2)){
					nodeMap.put(n,no);
				}
			} catch (GeometryException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}						
			}
		}
	}
	return nodeMap;   
}
 
Example 19
Project: c4a_data_repository   File: PrettyPrinter.java   Source Code and License 6 votes vote down vote up
/**
 * Pretty-prints an RDF node and shortens URIs into QNames according to a
 * {@link PrefixMapping}.
 * @param n An RDF node
 * @return An N-Triples style textual representation with URIs shortened to QNames
 */
public static String toString(Node n, PrefixMapping prefixes) {
	if (n.isURI()) {
		return qNameOrURI(n.getURI(), prefixes);
	}
	if (n.isBlank()) {
		return "_:" + n.getBlankNodeLabel();
	}
	if (n.isVariable()) {
		return "?" + n.getName();
	}
	if (Node.ANY.equals(n)) {
		return "?ANY";
	}
	// Literal
	String s = "\"" + n.getLiteralLexicalForm() + "\"";
	if (!"".equals(n.getLiteralLanguage())) {
		s += "@" + n.getLiteralLanguage();
	}
	if (n.getLiteralDatatype() != null) {
		s += "^^" + qNameOrURI(n.getLiteralDatatypeURI(), prefixes);
	}
	return s;
}
 
Example 20
Project: S2X   File: Expr2.java   Source Code and License 5 votes vote down vote up
/**
    * Check if a String is an Integer
    * 
    * @param toTest
    *            String to test
    * @return True if it is an integer, false otherwise
    */
   private Boolean isInteger(String toTest) {
if (toTest == null) {
    return false;
}

try {
    Node testNode = NodeFactoryExtra.parseNode(toTest);
    return testNode.toString().endsWith(
	    "^^http://www.w3.org/2001/XMLSchema#integer") ? true
	    : false;
} catch (Exception e) {
    return false;
}
   }
 
Example 21
Project: S2RDF   File: ReorderNoCross.java   Source Code and License 5 votes vote down vote up
private ArrayList<String> getVarsOfTriple(Triple t) {
    ArrayList<String> vars = new ArrayList<String>();
    Node subject = t.getSubject();
    Node predicate = t.getPredicate();
    Node object = t.getObject();
    if(subject.isVariable())
        vars.add(subject.getName());
    if(predicate.isVariable())
        vars.add(predicate.getName());
    if(object.isVariable())
        vars.add(object.getName());
    return vars;
}
 
Example 22
Project: S2RDF   File: TransformerHelper.java   Source Code and License 5 votes vote down vote up
public static BasicPattern transformPathToBasicPattern(Node subject, String sPath, Node object){
	BasicPattern res= new BasicPattern();
	boolean inverse = checkInverse(sPath);
	if (inverse)
	{
		sPath = sPath.substring(1);
		Node temp = subject;
		subject = object;
		object = temp;
	}
	sPath = TransformerHelper.removeScopes(sPath);
	int operatorPos = TransformerHelper.getPosOfNextOperator(sPath);
	if (operatorPos < 0)
	{
		Triple triple = new Triple(subject, NodeFactory.createURI(sPath.substring(1, sPath.length()-1)), object);
		res.add(triple);
		return res;
	}
   	String leftStringPath = sPath.substring(0, operatorPos);
   	String rightStringPath = sPath.substring(operatorPos+1);
   	Node newConection = NodeFactory.createVariable(getNextVaribleName());
   	BasicPattern leftPattern = transformPathToBasicPattern(subject, leftStringPath, newConection);
   	BasicPattern rightPattern = transformPathToBasicPattern(newConection, rightStringPath, object);
   	res.addAll(leftPattern);
   	res.addAll(rightPattern);
	return res;
}
 
Example 23
Project: PigSPARQL   File: ReorderNoCross.java   Source Code and License 5 votes vote down vote up
protected ArrayList<String> getVarsOfTriple(Triple t) {
	ArrayList<String> vars = new ArrayList<String>();
	Node subject = t.getSubject();
	Node predicate = t.getPredicate();
	Node object = t.getObject();
	if (subject.isVariable())
		vars.add(subject.getName());
	if (predicate.isVariable())
		vars.add(predicate.getName());
	if (object.isVariable())
		vars.add(object.getName());
	return vars;
}
 
Example 24
Project: PigSPARQL   File: PigBGP.java   Source Code and License 5 votes vote down vote up
protected ArrayList<String> getVarsOfTriple(Triple t) {
	ArrayList<String> vars = new ArrayList<String>();
	Node subject = t.getSubject();
	Node predicate = t.getPredicate();
	Node object = t.getObject();
	if (subject.isVariable())
		vars.add(subject.getName());
	if (predicate.isVariable())
		vars.add(predicate.getName());
	if (object.isVariable())
		vars.add(object.getName());
	return vars;
}
 
Example 25
Project: Sempala   File: ReorderNoCross.java   Source Code and License 5 votes vote down vote up
private ArrayList<String> getVarsOfTriple(Triple t) {
	ArrayList<String> vars = new ArrayList<String>();
	Node subject = t.getSubject();
	Node predicate = t.getPredicate();
	Node object = t.getObject();
	if(subject.isVariable())
		vars.add(subject.getName());
	if(predicate.isVariable())
		vars.add(predicate.getName());
	if(object.isVariable())
		vars.add(object.getName());
	return vars;
}
 
Example 26
Project: Sempala   File: ImpalaComplexTripleGroup.java   Source Code and License 5 votes vote down vote up
/**
 * From a triple the method extracts the variable names 
 * and the columns to be selected from the table referring to that variable.
 * 
 * @param t
 * @return
 */
private HashMap<String, String[]> getMappingVarsOfTriple(Triple t) {
	HashMap<String, String[]> result = new HashMap<String, String[]>();
	Node subject = t.getSubject();
	Node predicate = t.getPredicate();
	Node object = t.getObject();
	if (subject.isVariable()){
		result.put(subject.getName(),
				new String[] { Tags.SUBJECT_COLUMN_NAME });
	}
	if (predicate.isVariable()) {
		selectFromTripleStore = true;
		result.put(predicate.getName(),
				new String[] { Tags.PREDICATE_COLUMN_NAME });
	}
	if (object.isVariable()) {
		if (selectFromTripleStore) {
			result.put(object.getName(),
					new String[] { Tags.OBJECT_COLUMN_NAME });
		} else {
			String objectString = object.getName();
			String predicateString = getPropertyFromURI(FmtUtils
					.stringForNode(predicate, prefixMapping), false);
			
			
			result.put(objectString, new String[] { SpecialCharFilter
					.filter(predicateString) });
		}
	}
	return result;
}
 
Example 27
Project: marklogic-contentpump   File: RDFReader.java   Source Code and License 5 votes vote down vote up
protected String resource(Node rsrc) {
    if (rsrc.isBlank()) {
        return "http://marklogic.com/semantics/blank/" + Long.toHexString(
                    fuse(scramble((long)rsrc.hashCode()),fuse(scramble(milliSecs),randomValue)));
    } else {
        return escapeXml(rsrc.toString());
    }
}
 
Example 28
Project: BimSPARQL   File: IsOutsidePF.java   Source Code and License 5 votes vote down vote up
protected HashSet<Node> getInstanceOf(Node cls,Graph graph){
	HashSet<Node> nodes=new HashSet<Node>();
	ExtendedIterator<Triple> it=graph.find(null, RDF.type.asNode(), cls);
	while(it.hasNext()){
		nodes.add(it.next().getSubject());
	}
	return nodes;
}
 
Example 29
Project: BimSPARQL   File: HasGrossWallAreaPF.java   Source Code and License 5 votes vote down vote up
@Override
protected QueryIterator getValue(Binding binding, Graph graph, Node product, Geometry geometry, Var alloc,
		ExecutionContext execCxt) {
    double a=computeValueByMVBB(geometry);
    double b=computeValueBySurfaceArea(product,geometry,execCxt);
    double area=Double.min(a, b);
    if(area!=Double.NaN){
        Node node=NodeFactory.createLiteral(Double.toString(area),null,XSDDatatype.XSDdouble);
		return IterLib.oneResult(binding, alloc, node, execCxt);
		}else{
			return IterLib.noResults(execCxt);
		}
}
 
Example 30
Project: c4a_data_repository   File: ResourceDescriber.java   Source Code and License 5 votes vote down vote up
public Graph description() {
	if (executed) return result;
	executed = true;

	final QueryIterConcat qIter = new QueryIterConcat(context);
	Pingback<?> pingback = null;
	if (timeout > 0) {
		pingback = AlarmClock.get().add(new Callback<Object>() {
			public void proc(Object ignore) {
				qIter.cancel();
			}
		}, timeout);
	}
	
	FindQuery outgoing = new FindQuery(
			Triple.create(node, Node.ANY, Node.ANY), 
			mapping.compiledPropertyBridges(), limit, context);
	qIter.add(outgoing.iterator());
	
	if (!onlyOutgoing) {
		FindQuery incoming = new FindQuery(
				Triple.create(Node.ANY, Node.ANY, node), 
				mapping.compiledPropertyBridges(), limit, context);
		qIter.add(incoming.iterator());

		FindQuery triples = new FindQuery(
				Triple.create(Node.ANY, node, Node.ANY), 
				mapping.compiledPropertyBridges(), limit, context);
		qIter.add(triples.iterator());
	}
	result.getBulkUpdateHandler().add(TripleQueryIter.create(qIter));
	
	if (pingback != null) {
		AlarmClock.get().cancel(pingback);
	}
	
	return result;
}
 
Example 31
Project: marklogic-contentpump   File: RDFReader.java   Source Code and License 5 votes vote down vote up
protected String object(Node node) {
    if (node.isLiteral()) {
        String text = node.getLiteralLexicalForm();
        String type = node.getLiteralDatatypeURI();
        String lang = node.getLiteralLanguage();

        if (lang == null || "".equals(lang)) {
            lang = "";
        } else {
            lang = " xml:lang='" + escapeXml(lang) + "'";
        }

        if ("".equals(lang)) {
            if (type == null) {
                type = "http://www.w3.org/2001/XMLSchema#string";
            }
            type = " datatype='" + escapeXml(type) + "'";
        } else {
            type = "";
        }

        return "<sem:object" + type + lang + ">" + escapeXml(text) + "</sem:object>";
    } else if (node.isBlank()) {
        return "<sem:object>http://marklogic.com/semantics/blank/" + Long.toHexString(
                fuse(scramble((long)node.hashCode()),fuse(scramble(milliSecs),randomValue)))
                +"</sem:object>";
    } else {
        return "<sem:object>" + escapeXml(node.toString()) + "</sem:object>";
    }
}
 
Example 32
Project: r2rml-kit   File: JenaGraphExample.java   Source Code and License 5 votes vote down vote up
public static void main(String[] args) {
	// Load mapping file
	Model mapModel = FileManager.get().loadModel("doc/example/mapping-iswc.ttl");
	
	// Read mapping file
	D2RQReader reader = new D2RQReader(mapModel, "http://localhost:2020/");
	Mapping mapping = reader.getMapping();
	
	// Compile mapping for D2RQ engine
	CompiledMapping compiled = mapping.compile();

	// Set up the GraphD2RQ
	GraphD2RQ g = new GraphD2RQ(compiled);

	// Create a find(spo) pattern 
	Node subject = Node.ANY;
	Node predicate = DC.date.asNode();
	Node object = Node.createLiteral("2003", null, XSDDatatype.XSDgYear);
	Triple pattern = new Triple(subject, predicate, object);

	// Query the graph
	Iterator<Triple> it = g.find(pattern);
	
	// Output query results
	while (it.hasNext()) {
		Triple t = it.next();
	    System.out.println("Published in 2003: " + t.getSubject());
	}
	g.close();
}
 
Example 33
Project: c4a_data_repository   File: HSQLSimpleTest.java   Source Code and License 5 votes vote down vote up
public void testGenerateTripleFromSimpleD2RQMapping() {
	Mapping m = MappingHelper.readFromTestFile("helpers/simple.ttl");
	m.configuration().setServeVocabulary(false);
	db.executeSQL("INSERT INTO TEST VALUES (1, 'Hello World!')");
	GraphD2RQ g = new GraphD2RQ(m);
	assertTrue(g.contains(
			Node.createURI(EX + "test/1"), RDF.Nodes.type, Node.createURI(EX + "Test")));
	assertEquals(1, g.size());
}
 
Example 34
Project: r2rml-kit   File: TypedNodeMaker.java   Source Code and License 5 votes vote down vote up
public Node makeNode(ResultRow tuple) {
	String value = this.valueMaker.makeValue(tuple);
	if (value == null) {
		return null;
	}
	return this.nodeType.makeNode(value);
}
 
Example 35
Project: BimSPARQL   File: HasUpperStoreyPF.java   Source Code and License 5 votes vote down vote up
@Override
protected HashSet<Node> getRelatedSubjects(Node node, ExecutionContext execCxt) {
	HashSet<Node> results = new HashSet<Node>();

	Graph graph = execCxt.getActiveGraph();

	Node clazz = NodeFactory.createURI(Namespace.IFC2X3_TC1 + "IfcBuildingStorey");
	LinkedList<Storey> storeys = new LinkedList<Storey>();
	if (graph.contains(node, RDF.type.asNode(), clazz)) {
		Storey storey = new Storey(node, elevation(node, graph));
		if (storey.elevation == Double.NaN) {
			return results;
		}
		ExtendedIterator<Triple> triples = graph.find(null, RDF.type.asNode(), clazz);
		while (triples.hasNext()) {
			Node subject = triples.next().getSubject();
			Storey s = new Storey(subject, elevation(subject, graph));
			if (s.elevation != Double.NaN) {
				if (s.elevation < storey.elevation) {
					addStorey(storeys, s, graph);
				}
			}
		}
		if (storeys.size() > 0) {
			results.add(storeys.get(storeys.size() - 1).storey);
		}
	}
	return results;

}
 
Example 36
Project: c4a_data_repository   File: FixedNodeMaker.java   Source Code and License 5 votes vote down vote up
public NodeMaker selectNode(Node n, RelationalOperators sideEffects) {
	if (n.equals(this.node) || n.equals(Node.ANY) || n.isVariable()) {
		return this;
	}
	sideEffects.select(Expression.FALSE);
	return NodeMaker.EMPTY;
}
 
Example 37
Project: c4a_data_repository   File: ResourceDescriber.java   Source Code and License 5 votes vote down vote up
public ResourceDescriber(Mapping mapping, Node resource, boolean onlyOutgoing, int limit, long timeout) {
	this.mapping = mapping;
	this.node = resource;
	this.onlyOutgoing = onlyOutgoing;
	this.limit = limit;
	this.timeout = timeout;
	this.context = null;
}
 
Example 38
Project: r2rml-kit   File: CompiledD2RQMapping.java   Source Code and License 5 votes vote down vote up
public List<String> getResourceCollectionNames(Node forNode) {
	List<String> result = new ArrayList<String>();
	for (String name: resourceCollections.keySet()) {
		if (resourceCollections.get(name).mayContain(forNode)) {
			result.add(name);
		}
	}
	Collections.sort(result);
	return result;
}
 
Example 39
Project: c4a_data_repository   File: ClassMapLister.java   Source Code and License 5 votes vote down vote up
public Collection<String> classMapNamesForResource(Node resource) {
	if (!resource.isURI()) {
		return Collections.<String>emptyList();
	}
	List<String> results = new ArrayList<String>();
	for (Entry<String,NodeMaker> entry: classMapNodeMakers.entrySet()) {
		String classMapName = entry.getKey();
		NodeMaker nodeMaker = entry.getValue();
		if (!nodeMaker.selectNode(resource, RelationalOperators.DUMMY).equals(NodeMaker.EMPTY)) {
			results.add(classMapName);
		}
	}
	return results;
}
 
Example 40
Project: r2rml-kit   File: R2RMLCompiler.java   Source Code and License 5 votes vote down vote up
public List<String> getResourceCollectionNames(Node forNode) {
	checkCompiled();
	List<String> result = new ArrayList<String>();
	for (String name: resourceCollections.keySet()) {
		if (resourceCollections.get(name).mayContain(forNode)) {
			result.add(name);
		}
	}
	Collections.sort(result);
	return result;
}