Java Code Examples for org.openrdf.model.Literal#getDatatype()

The following examples show how to use org.openrdf.model.Literal#getDatatype() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MathUtility.java    From database with GNU General Public License v2.0 6 votes vote down vote up
public static boolean checkNumericDatatype(final Literal... args) {
	for (Literal lit : args) {
		final URI dt = lit.getDatatype();

		if (dt == null)
		    return false;
		
		boolean isNumeric = false;
		isNumeric |= XMLDatatypeUtil.isNumericDatatype(dt);
		isNumeric |= dt.equals(CompressedTimestampExtension.COMPRESSED_TIMESTAMP);
		
		if (!isNumeric)
			return false;
	}
	return true;
}
 
Example 2
Source File: ColorsEnumExtension.java    From database with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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 LiteralExtensionIV} is returned that
 * wraps the native type.
 */
public LiteralExtensionIV 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;
    try {
        c = Enum.valueOf(Color.class, s);
    } catch (IllegalArgumentException ex) {
        // not a valid color
        return null;
    }
    
    final AbstractLiteralIV delegate = new XSDNumericIV(c.getByte());

    return new LiteralExtensionIV(delegate, color.getIV());
    
}
 
Example 3
Source File: LiteralManager.java    From anno4j with Apache License 2.0 5 votes vote down vote up
public Object createObject(Literal literal) {
	URI datatype = literal.getDatatype();
	if (datatype == null) {
		if (literal.getLanguage() == null) {
			datatype = STRING;
		} else {
			datatype = LANG_STRING;
		}
	}
	Marshall<?> marshall = findMarshall(datatype);
	return marshall.deserialize(literal);
}
 
Example 4
Source File: ConstVar.java    From neo4j-sparql-extension with GNU General Public License v3.0 5 votes vote down vote up
public ConstVar(Value value) {
	if (value == null) {
		throw new IllegalArgumentException("value can not be null");
	}

	String uniqueStringForValue = value.stringValue();

	if (value instanceof Literal) {
		uniqueStringForValue += "-lit";

		// we need to append datatype and/or language tag to ensure a unique var name (see SES-1927)
		Literal lit = (Literal) value;
		if (lit.getDatatype() != null) {
			uniqueStringForValue += "-" + lit.getDatatype().stringValue();
		}
		if (lit.getLanguage() != null) {
			uniqueStringForValue += "-" + lit.getLanguage();
		}
	} else if (value instanceof BNode) {
		uniqueStringForValue += "-node";
	} else {
		uniqueStringForValue += "-uri";
	}
	setName("-const-" + uniqueStringForValue);
	setConstant(true);
	setAnonymous(true);
	setValue(value);
}
 
Example 5
Source File: CumulusRDFValueFactory.java    From cumulusrdf with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a CumulusRDF native value from a given {@link Value}.
 * 
 * @param value the incoming {@link Value}.
 * @return a CumulusRDF native value.
 */
public static Value makeNativeValue(final Value value) {
	if (value == null || value instanceof INativeCumulusValue) {
		return value;
	}

	if (value instanceof URI) {
		return new NativeCumulusURI(value.stringValue());
	} else if (value instanceof Literal) {
		
		final Literal lit = (Literal) value;
		final String label = lit.getLabel(), language = lit.getLanguage();
		final URI datatype = lit.getDatatype();

		if (language != null) {
			return new NativeCumulusLiteral(label, language);
		} else if (datatype != null) {
			return new NativeCumulusLiteral(label, datatype);
		} else {
			return new NativeCumulusLiteral(label);
		}
		
	} else if (value instanceof BNode) {
		return new NativeCumulusBNode(value.stringValue());
	}

	return value;
}
 
Example 6
Source File: XsdUnsignedLongBOp.java    From database with GNU General Public License v2.0 5 votes vote down vote up
public IV get(final IBindingSet bs) {

        final IV iv = getAndCheckBound(0, bs);
        
        if (log.isDebugEnabled()) {
        	log.debug(iv);
        }
        
        final Value val = asValue(iv);

        if (log.isDebugEnabled()) {
        	log.debug(val);
        }
        
        // use to create my simple literals
        final BigdataValueFactory vf = getValueFactory();

        try {
            if (val instanceof Literal) {
            	final Literal lit = (Literal) val;
                if (lit.getDatatype() != null && lit.getDatatype().equals(XSD.UNSIGNED_LONG)) {
                    // if xsd:unsignedLong literal return it
                    return iv;
            	}
            	else {
            	    final BigInteger valAsBigInt = new BigInteger(lit.getLabel());
            	    if (valAsBigInt.compareTo(MIN_UNSIGNED_LONG)>=0 && valAsBigInt.compareTo(MAX_UNSIGNED_LONG)<=0) {
                        final BigdataLiteral str = 
                            vf.createLiteral(String.valueOf(valAsBigInt.toString()), XSD.UNSIGNED_LONG);
                        return super.asIV(str, bs);
            	    }
                }
            }
        } catch (Exception e) {
            // exception handling following
        }

        throw new SparqlTypeErrorException(); // fallback
    }
 
Example 7
Source File: GeoSpatialServiceFactory.java    From database with GNU General Public License v2.0 5 votes vote down vote up
PointLatLon resolveAsPoint(final TermNode termNode, final IBindingSet bs) {

            final Literal lit = resolveAsLiteral(termNode, bs);
            if (lit == null || lit.stringValue().isEmpty()) {
                return null;
            }

            final String pointAsStr = lit.stringValue();
            IGeoSpatialLiteralSerializer serializer = null;
            GeoSpatialDatatypeConfiguration pconfig = null;

            if (lit.getDatatype() != null) {
                // If we have datatype that can extract coordinates, use it to exteract
                pconfig = geoSpatialConfig.getConfigurationForDatatype(lit.getDatatype());
                if (pconfig.hasLat() && pconfig.hasLon()) {
                    serializer = pconfig.getLiteralSerializer();
                }
            }

            try {
                
                if (serializer == null) {
                    
                  return new PointLatLon(pointAsStr);

                } else {
                    
                    final String[] comps = serializer.toComponents(pointAsStr);
                    final Double lat = Double.parseDouble(comps[pconfig.idxOfField(ServiceMapping.LATITUDE)]);
                    final Double lon = Double.parseDouble(comps[pconfig.idxOfField(ServiceMapping.LONGITUDE)]);
                    return new PointLatLon(lat, lon);
                
                }
                
            } catch (NumberFormatException e) {

                throw new GeoSpatialSearchException("Input could not be resolved as point: '" + pointAsStr + "'.");
            }
        }
 
Example 8
Source File: DigestBOp.java    From database with GNU General Public License v2.0 4 votes vote down vote up
@Override
public IV get(final IBindingSet bs) throws SparqlTypeErrorException {

    final IV iv = getAndCheckLiteral(0, bs);
    //Recreate since they are not thread safe
    MessageDigest md = null;
    final Literal lit = asLiteral(iv);
    if (lit.getLanguage() == null &&
        (lit.getDatatype() == null || lit.getDatatype().equals(XSD.STRING))) {
        
        try {
            String label = lit.getLabel();
            switch (op()) {
            case MD5:
                md = MessageDigest.getInstance("MD5");
                break;
            case SHA1:
                md = MessageDigest.getInstance("SHA-1");
                break;
            case SHA224:
                md = MessageDigest.getInstance("SHA-224");
                break;
            case SHA256:
                md = MessageDigest.getInstance("SHA-256");
                break;
            case SHA384:
                md = MessageDigest.getInstance("SHA-384");
                break;
           case SHA512:
                md = MessageDigest.getInstance("SHA-512");
                break;
            default:
                throw new UnsupportedOperationException();
            }
            byte[] bytes = label.getBytes("UTF-8");
            md.update(bytes);
            byte[] digest = md.digest();
            final BigdataLiteral str = getValueFactory().createLiteral(toHexString(digest));
            return super.asIV(str, bs);
        } catch (Exception e) {
            throw new SparqlTypeErrorException();
        }
    }
    throw new SparqlTypeErrorException();
}
 
Example 9
Source File: DateTimeExtension.java    From database with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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 LiteralExtensionIV} to wrap the native
 * type.
 */
public LiteralExtensionIV createIV(final Value value) {
    
    if (value instanceof Literal == false)
        throw new IllegalArgumentException();
    
    final Literal lit = (Literal) value;
    
    final URI dt = lit.getDatatype();
    
    final String s = value.stringValue();
    
    /*
     * Returns the current time as UTC milliseconds from the epoch
     */
    final long l = getTimestamp(s, defaultTZ);
    
    return createIV(l, dt);
    
}
 
Example 10
Source File: NumericBOp.java    From database with GNU General Public License v2.0 4 votes vote down vote up
@SuppressWarnings("rawtypes")
public IV get(final IBindingSet bs) {
    
	final Literal lit = super.getAndCheckLiteralValue(0, bs);
	
	final URI dt = lit.getDatatype();
	
	final NumericOp op = op();
	
	if ((dt.equals(XMLSchema.INT) || dt.equals(XMLSchema.INTEGER)) &&
	    (op == NumericOp.CEIL || op == NumericOp.FLOOR || op == NumericOp.ROUND)) {
	    
	    return get(0).get(bs);
	            
	}
	
	if (log.isDebugEnabled())
		log.debug(lit);
	
    return MathUtility.numericalFunc(lit, op());
    
}
 
Example 11
Source File: WebTestUtils.java    From cumulusrdf with Apache License 2.0 4 votes vote down vote up
/**
 * Copied from org.openrdf.query.QueryResultUtil
 */
private static boolean bindingSetsMatch(final BindingSet bs1, final BindingSet bs2) {

	if (bs1.size() != bs2.size()) {
		return false;
	}

	for (Binding binding1 : bs1) {
		Value value1 = binding1.getValue();
		Value value2 = bs2.getValue(binding1.getName());

		if ((value1 instanceof BNode) && (value2 instanceof BNode)) {
			// BNode mappedBNode = bNodeMapping.get(value1);
			//
			// if (mappedBNode != null) {
			// // bNode 'value1' was already mapped to some other bNode
			// if (!value2.equals(mappedBNode)) {
			// // 'value1' and 'value2' do not match
			// return false;
			// }
			// } else {
			// // 'value1' was not yet mapped, we need to check if 'value2'
			// // is a
			// // possible mapping candidate
			// if (bNodeMapping.containsValue(value2)) {
			// // 'value2' is already mapped to some other value.
			// return false;
			// }
			// }

			return value1.equals(value2);
		} else {
			// values are not (both) bNodes
			if ((value1 instanceof Literal) && (value2 instanceof Literal)) {
				// do literal value-based comparison for supported datatypes
				Literal leftLit = (Literal) value1;
				Literal rightLit = (Literal) value2;

				URI dt1 = leftLit.getDatatype();
				URI dt2 = rightLit.getDatatype();

				if ((dt1 != null) && (dt2 != null) && dt1.equals(dt2) && XMLDatatypeUtil.isValidValue(leftLit.getLabel(), dt1)
						&& XMLDatatypeUtil.isValidValue(rightLit.getLabel(), dt2)) {
					Integer compareResult = null;
					if (dt1.equals(XMLSchema.DOUBLE)) {
						compareResult = Double.compare(leftLit.doubleValue(), rightLit.doubleValue());
					} else if (dt1.equals(XMLSchema.FLOAT)) {
						compareResult = Float.compare(leftLit.floatValue(), rightLit.floatValue());
					} else if (dt1.equals(XMLSchema.DECIMAL)) {
						compareResult = leftLit.decimalValue().compareTo(rightLit.decimalValue());
					} else if (XMLDatatypeUtil.isIntegerDatatype(dt1)) {
						compareResult = leftLit.integerValue().compareTo(rightLit.integerValue());
					} else if (dt1.equals(XMLSchema.BOOLEAN)) {
						Boolean leftBool = Boolean.valueOf(leftLit.booleanValue());
						Boolean rightBool = Boolean.valueOf(rightLit.booleanValue());
						compareResult = leftBool.compareTo(rightBool);
					} else if (XMLDatatypeUtil.isCalendarDatatype(dt1)) {
						XMLGregorianCalendar left = leftLit.calendarValue();
						XMLGregorianCalendar right = rightLit.calendarValue();

						compareResult = left.compare(right);
					}

					if (compareResult != null) {
						if (compareResult.intValue() != 0) {
							return false;
						}
					} else if (!value1.equals(value2)) {
						return false;
					}
				} else if (!value1.equals(value2)) {
					return false;
				}
			} else if (!value1.equals(value2)) {
				return false;
			}
		}
	}

	return true;
}
 
Example 12
Source File: IVComparator.java    From database with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Taken directly from Sesame's ValueComparator, no modification.  Handles
 * inlines nicely since they now implement the Literal interface.
 */
private int compareLiterals(final Literal leftLit, final Literal rightLit) {
	// Additional constraint for ORDER BY: "A plain literal is lower
	// than an RDF literal with type xsd:string of the same lexical
	// form."

	if (!QueryEvaluationUtil.isStringLiteral(leftLit) || !QueryEvaluationUtil.isStringLiteral(rightLit)) {
		try {
			boolean isSmaller = QueryEvaluationUtil.compareLiterals(leftLit, rightLit, CompareOp.LT);

			if (isSmaller) {
				return -1;
			}
			else {
				return 1;
			}
		}
		catch (ValueExprEvaluationException e) {
			// literals cannot be compared using the '<' operator, continue
			// below
		}
	}

	int result = 0;

	// Sort by datatype first, plain literals come before datatyped literals
	URI leftDatatype = leftLit.getDatatype();
	URI rightDatatype = rightLit.getDatatype();

	if (leftDatatype != null) {
		if (rightDatatype != null) {
			// Both literals have datatypes
			result = compareDatatypes(leftDatatype, rightDatatype);
		}
		else {
			result = 1;
		}
	}
	else if (rightDatatype != null) {
		result = -1;
	}

	if (result == 0) {
		// datatypes are equal or both literals are untyped; sort by language
		// tags, simple literals come before literals with language tags
		String leftLanguage = leftLit.getLanguage();
		String rightLanguage = rightLit.getLanguage();

		if (leftLanguage != null) {
			if (rightLanguage != null) {
				result = leftLanguage.compareTo(rightLanguage);
			}
			else {
				result = 1;
			}
		}
		else if (rightLanguage != null) {
			result = -1;
		}
	}

	if (result == 0) {
		// Literals are equal as fas as their datatypes and language tags are
		// concerned, compare their labels
		result = leftLit.getLabel().compareTo(rightLit.getLabel());
	}

	return result;
}
 
Example 13
Source File: EpochExtension.java    From database with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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 LiteralExtensionIV} to wrap the native
 * type.
 */
public LiteralExtensionIV 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);
    
    final AbstractLiteralIV delegate = new XSDNumericIV(l);

    return new LiteralExtensionIV(delegate, epoch.getIV());
    
}
 
Example 14
Source File: BigdataSubjectCentricFullTextIndex.java    From database with GNU General Public License v2.0 4 votes vote down vote up
public void index(final IV<?,?> subject,
            final Iterator<BigdataValue> valuesIterator) {
        
    	if (subject == null) {
    		throw new IllegalArgumentException();
    	}
    	
    	if (log.isDebugEnabled()) {
    		log.debug("indexing: " + subject);
    	}
    	
    	/*
    	 * We can use a capacity of one, because we will be indexing exactly
    	 * one subject.
    	 */
        final TokenBuffer<?> buffer = new TokenBuffer(1, this);

        int n = 0;
        
        while (valuesIterator.hasNext()) {

            final BigdataValue val = valuesIterator.next();

        	if (log.isDebugEnabled()) {
        		log.debug("value: " + val);
        	}
        	
            if (!(val instanceof Literal)) {

                /*
                 * Note: If you allow URIs to be indexed then the code which is
                 * responsible for free text search for quads must impose a
                 * filter on the subject and predicate positions to ensure that
                 * free text search can not be used to materialize literals or
                 * URIs from other graphs. This matters when the named graphs
                 * are used as an ACL mechanism. This would also be an issue if
                 * literals were allowed into the subject position.
                 */
                continue;

            }

            final Literal lit = (Literal) val;

            if (!indexDatatypeLiterals && lit.getDatatype() != null) {

                // do not index datatype literals in this manner.
                continue;

            }

            final String languageCode = lit.getLanguage();

            // Note: May be null (we will index plain literals).
            // if(languageCode==null) continue;

            final String text = lit.getLabel();

            /*
             * Note: The OVERWRITE option is turned off to avoid some of the
             * cost of re-indexing each time we see a term.
             */

//            // don't bother text indexing inline values for now
//            if (termId.isInline()) {
//                continue;
//            }
            
            index(buffer, subject, 0/* fieldId */, languageCode,
                    new StringReader(text));

            n++;

        }
        
        // flush writes to the text index.
        buffer.flush();

        if (log.isInfoEnabled())
            log.info("indexed " + n + " new values for s: " + subject);

    }
 
Example 15
Source File: ConcatBOp.java    From database with GNU General Public License v2.0 4 votes vote down vote up
@Override
public IV get(final IBindingSet bs) {
    URI datatype = null;
    String lang = null;
    boolean allSame = true;
    final StringBuilder sb = new StringBuilder();
    for (int i = 0; i < arity(); i++) {
        @SuppressWarnings("rawtypes")
        final IV v = getAndCheckLiteral(i, bs);

        if (v.isNumeric()) {
            throw new SparqlTypeErrorException();
        }
        
        String label = null;
        if (allSame) {
            final Literal lit = asLiteral(v);
            label = lit.getLabel();
            if (lit.getDatatype() != null) {
                if (lang != null) {
                    allSame = false;
                } else if (datatype == null) {
                    if (i == 0) {
                        datatype = lit.getDatatype();
                    } else {
                        allSame = false;
                    }
                } else if (!datatype.equals(lit.getDatatype())) {
                    allSame = false;
                }
            } else if (lit.getLanguage() != null) {
                if (datatype != null) {
                    allSame = false;
                } else if (lang == null) {
                    if (i == 0) {
                        lang = lit.getLanguage();
                    } else {
                        allSame = false;
                    }
                } else if (!lang.equals(lit.getLanguage())) {
                    allSame = false;
                }
            } else {
                allSame = false;
            }
        } else {
            label = literalLabel(v);
        }
        sb.append(label);
    }
    if (allSame) {
        if (datatype != null) {
            return super.asIV(getValueFactory().createLiteral(sb.toString(),datatype), bs);
        } else if (lang != null) {
            return super.asIV(getValueFactory().createLiteral(sb.toString(),lang), bs);
        }
    }
    return super.asIV(getValueFactory().createLiteral(sb.toString()), bs);

}
 
Example 16
Source File: BigdataValueSerializer.java    From database with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Return the total #of characters in the RDF {@link Value}.
 * 
 * @param v
 *            The {@link Value}.
 * 
 * @return The character length of the data in the RDF {@link Value}.
 */
static public long getStringLength(final Value v) {

    if (v == null)
        throw new IllegalArgumentException();
    
    if (v instanceof URI) {

        return ((URI) v).stringValue().length();

    } else if (v instanceof Literal) {

        final Literal value = (Literal) v;

        final String label = value.getLabel();

        final int datatypeLength = value.getDatatype() == null ? 0 : value
                .getDatatype().stringValue().length();

        final int languageLength = value.getLanguage() == null ? 0 : value
                .getLanguage().length();

        final long totalLength = label.length() + datatypeLength
                + languageLength;

        return totalLength;

    } else if (v instanceof BNode) {

        return ((BNode) v).getID().length();

    } else {
        
        throw new UnsupportedOperationException();
        
    }
    
}
 
Example 17
Source File: Utility.java    From cumulusrdf with Apache License 2.0 3 votes vote down vote up
/**
 * Parses a given literal as a XSD datetime.
 * 
 * @param lit the literal.
 * @return the datetime representation of the given literal (in msecs).
 */
public static long parseXMLSchemaDateTimeAsMSecs(final Literal lit) {

	if (lit == null) {
		throw new IllegalArgumentException("literal was null");
	}

	URI dt = lit.getDatatype();

	if (dt == null) {
		throw new IllegalArgumentException("no datatype given");
	}

	if (dt.equals(XML_SCHEMA_DATE)) {

		return ISODateTimeFormat.dateParser().parseMillis(lit.getLabel());

	} else if (dt.equals(XML_SCHEMA_DATE_TIME)) {

		return ISODateTimeFormat.dateTimeParser().parseMillis(lit.getLabel());

	} else if (dt.equals(XML_SCHEMA_TIME)) {

		return ISODateTimeFormat.timeParser().parseMillis(lit.getLabel());

	} else {
		throw new IllegalArgumentException("datatype unknown: " + dt);
	}
}
 
Example 18
Source File: LcaseBOp.java    From database with GNU General Public License v2.0 3 votes vote down vote up
@Override
public IV get(final IBindingSet bs) {

    final Literal in = getAndCheckLiteralValue(0, bs);

    final BigdataValueFactory vf = getValueFactory();

    final String label = in.getLabel().toLowerCase();

    final BigdataLiteral out;

    if (in.getLanguage() != null) {

        out = vf.createLiteral(label, in.getLanguage());

    } else if (in.getDatatype() != null) {

        out = vf.createLiteral(label, in.getDatatype());

    } else {

        out = vf.createLiteral(label);
        
    }

    return super.asIV(out, bs);

}
 
Example 19
Source File: BigdataValueFactoryImpl.java    From database with GNU General Public License v2.0 2 votes vote down vote up
@Override
 final public BigdataValue asValue(final Value v) {

     if (v == null)
         return null;

     if (v instanceof BigdataValueImpl
             && ((BigdataValueImpl) v).getValueFactory() == this) {

final BigdataValueImpl v1 = (BigdataValueImpl) v;

final IV<?, ?> iv = v1.getIV();

if (iv == null || !iv.isNullIV()) {

	/*
	 * A value from the same value factory whose IV is either
	 * unknown or defined (but not a NullIV or DummyIV).
	 */

	return (BigdataValue) v;

}

     }

     if (v instanceof BooleanLiteralImpl) {
     	
 		final BooleanLiteralImpl bl = (BooleanLiteralImpl) v;
 		
         return createLiteral(bl.booleanValue());

     } else if (v instanceof URI) {
     	
         return createURI(((URI) v).stringValue());
         
     } else if (v instanceof BigdataBNode && ((BigdataBNode)v).isStatementIdentifier()) {

    		return createBNode(((BigdataBNode) v).getStatement());

     } else if (v instanceof BNode) {

         return createBNode(((BNode) v).stringValue());

     } else if (v instanceof Literal) {

         final Literal tmp = ((Literal) v);

         final String label = tmp.getLabel();

         final String language = tmp.getLanguage();

         final URI datatype = tmp.getDatatype();

         return new BigdataLiteralImpl(//
                 this,// Note: Passing in this factory!
                 label,//
                 language,//
                 (BigdataURI)asValue(datatype)//
                 );

     } else {

         throw new AssertionError();

     }

 }
 
Example 20
Source File: DatatypeBOp.java    From database with GNU General Public License v2.0 2 votes vote down vote up
public IV get(final IBindingSet bs) {

	    final BigdataValueFactory vf = super.getValueFactory();

        @SuppressWarnings("rawtypes")
        final IV iv = getAndCheckLiteral(0, bs);

        // not yet bound
        if (iv == null)
        	throw new SparqlTypeErrorException();

        if (log.isDebugEnabled()) {
            log.debug(iv);
        }

        /*
         * We don't need to do this anymore.  asValue(IV) does the right thing,
         * it will let us work with the IV directly in the right cases.  The
         * BOps should no longer be doing this kind of logic directly.
         */
//        if (iv.isInline() && !iv.isExtension()) {
//
//        	return asIV(iv.getDTE().getDatatypeURI(), bs);
//        	
//        }

        final Value val = asValue(iv);

        if (val instanceof Literal) {

        	final Literal literal = (Literal) val;

        	final URI datatype;

			if (literal.getDatatype() != null) {

				// literal with datatype
				datatype = literal.getDatatype();

            } else if (literal.getLanguage() != null) {

                // language-tag literal
                datatype = RDF.LANGSTRING;

			} else if (literal.getLanguage() == null) {

				// simple literal
				datatype = XSD.STRING;

			} else {

				throw new SparqlTypeErrorException();

			}

	    	return asIV(datatype, bs);

        }

        throw new SparqlTypeErrorException();

    }