public TypeRequirementVisitor(String varName, Resource requiredType) { final Var typeVar = VarNameUtils.createUniqueConstVar(requiredType); typeVar.setConstant(true); this.varName = varName; if (BASE_TYPES.contains(requiredType)) { this.typeRequirement = null; } else { this.typeRequirement = new StatementPattern(new Var(varName), RDF_TYPE_VAR, typeVar); } } @Override
/** * Creates an (anonymous) Var representing a constant value. The variable name will be derived from the * actual value to guarantee uniqueness. * * @param value * @return an (anonymous) Var representing a constant value. */ public static Var createConstVar(Value value) { String varName = getConstVarName(value); Var var = new Var(varName); var.setConstant(true); var.setAnonymous(true); var.setValue(value); return var; }
/** * Creates an (anonymous) Var representing a constant value. The variable name will be derived from the * actual value to guarantee uniqueness. * * @param value * @return an (anonymous) Var representing a constant value. */ public static Var createConstVar(Value value) { String varName = getConstVarName(value); Var var = new Var(varName); var.setConstant(true); var.setAnonymous(true); var.setValue(value); return var; }
final String valueString = VarNameUtils.removeConstant(name); final Var var = new Var(name, vf.createIRI(valueString)); var.setConstant(true); return var; } else if(dataTypeString.equals(RyaSchema.BNODE_NAMESPACE)) { final Literal value = vf.createLiteral(valueString, dataType); final Var var = new Var(name, value); var.setConstant(true); return var;
@Test public void toVar_uri() { // Setup the string representation of the variable. final String varString = String.format(prependConstant("http://Chipotle%s%s"),TYPE_DELIM,XMLSchema.ANYURI ); // Convert it to a Var object. final Var var = FluoStringConverter.toVar(varString); // Ensure it converted to the expected result. final Var expected = new Var(prependConstant("http://Chipotle"), VF.createIRI("http://Chipotle")); expected.setConstant(true); assertEquals(expected, var); }
@Test public void toVar_int() throws MalformedQueryException { // Setup the string representation of the variable. final String varString = prependConstant("5<<~>>http://www.w3.org/2001/XMLSchema#integer"); // Convert it to a Var object. final Var result = FluoStringConverter.toVar(varString); // Ensure it converted to the expected result. final Var expected = new Var(prependConstant("5"), VF.createLiteral("5", XMLSchema.INTEGER)); expected.setConstant(true); assertEquals(expected, result); }
@Test public void toVar_string() { // Setup the string representation of the variable. final String varString = prependConstant("Chipotle<<~>>http://www.w3.org/2001/XMLSchema#string"); // Convert it to a Var object. final Var result = FluoStringConverter.toVar(varString); // Ensure it converted to the expected result. final Var expected = new Var(prependConstant("Chipotle"), VF.createLiteral("Chipotle", XMLSchema.STRING)); expected.setConstant(true); assertEquals(expected, result); } }
@Test public void statementPatternToString() throws MalformedQueryException { // Setup a StatementPattern that represents "?x <http://worksAt> <http://Chipotle>." final Var subject = new Var("x"); final Var predicate = new Var(prependConstant("http://worksAt"), VF.createIRI("http://worksAt")); predicate.setConstant(true); final Var object = new Var(prependConstant("http://Chipotle"), VF.createIRI("http://Chipotle")); object.setConstant(true); final StatementPattern pattern = new StatementPattern(subject, predicate, object); // Convert the pattern to a String. final String spString = FluoStringConverter.toStatementPatternString(pattern); // Ensure it converted to the expected result. final String expected = "x:::" + prependConstant("http://worksAt<<~>>http://www.w3.org/2001/XMLSchema#anyURI:::") + prependConstant("http://Chipotle<<~>>http://www.w3.org/2001/XMLSchema#anyURI"); assertEquals(spString, expected); }
@Test public void stringToStatementPattern() { // Setup the String representation of a statement pattern. final String patternString = "x:::" + prependConstant("http://worksAt<<~>>http://www.w3.org/2001/XMLSchema#anyURI:::") + prependConstant("http://Chipotle<<~>>http://www.w3.org/2001/XMLSchema#anyURI"); // Convert it to a StatementPattern. final StatementPattern statementPattern = FluoStringConverter.toStatementPattern(patternString); // Enusre it converted to the expected result. final Var subject = new Var("x"); final Var predicate = new Var(prependConstant("http://worksAt"), VF.createIRI("http://worksAt")); predicate.setConstant(true); final Var object = new Var(prependConstant("http://Chipotle"), VF.createIRI("http://Chipotle")); object.setConstant(true); final StatementPattern expected = new StatementPattern(subject, predicate, object); assertEquals(expected, statementPattern); }