You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stanbol.apache.org by sf...@apache.org on 2010/12/12 16:13:37 UTC
svn commit: r1044832 [6/14] - in /incubator/stanbol/trunk/rick:
indexing/dbPedia/src/main/java/eu/iksproject/rick/indexing/dbPedia/cli/
indexing/genericRdf/src/main/java/eu/iksproject/rick/indexing/rdf/
indexing/geonames/src/main/java/eu/iksproject/ric...
Modified: incubator/stanbol/trunk/rick/model/clerezza/src/main/java/eu/iksproject/rick/model/clerezza/impl/LiteralAdapter.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/rick/model/clerezza/src/main/java/eu/iksproject/rick/model/clerezza/impl/LiteralAdapter.java?rev=1044832&r1=1044831&r2=1044832&view=diff
==============================================================================
--- incubator/stanbol/trunk/rick/model/clerezza/src/main/java/eu/iksproject/rick/model/clerezza/impl/LiteralAdapter.java (original)
+++ incubator/stanbol/trunk/rick/model/clerezza/src/main/java/eu/iksproject/rick/model/clerezza/impl/LiteralAdapter.java Sun Dec 12 15:13:35 2010
@@ -23,6 +23,8 @@ import eu.iksproject.rick.servicesapi.mo
* data type constrained in {@link RdfResourceUtils#STRING_DATATYPES} to Text instances
* <li> Int, Long, UriRef ... : Converts {@link TypedLiteral}s to the according
* Java Object by using the Clerezza {@link LiteralFactory} (see {@link SimpleLiteralFactory})
+ * </ul>
+ *
* @author Rupert Westenthaler
*
* @param <T> All types of Literals
@@ -30,45 +32,47 @@ import eu.iksproject.rick.servicesapi.mo
*/
public class LiteralAdapter<T extends Literal,A> implements Adapter<T, A> {
- static Logger log = LoggerFactory.getLogger(LiteralAdapter.class);
- LiteralFactory lf = LiteralFactory.getInstance();
- RdfValueFactory valueFactory = RdfValueFactory.getInstance();
- @SuppressWarnings("unchecked")
- @Override
- public A adapt(T value, Class<A> type) {
- if(type.equals(String.class)){
- return (A) value.getLexicalForm();
- } else if(Text.class.isAssignableFrom(type)){
- if(value instanceof PlainLiteral ||
- (value instanceof TypedLiteral &&
- RdfResourceUtils.STRING_DATATYPES.contains(((TypedLiteral)value).getDataType()))){
- return (A)valueFactory.createText(value);
- } else { //this Literal can not be converted to Text!
- if(value instanceof TypedLiteral){ //TODO: maybe remove this debugging for performance reasons
- log.debug("TypedLiterals of type "+((TypedLiteral)value).getDataType()+" can not be converted to Text");
- } else {
- log.warn("Literal of type"+value.getClass()+" are not supported by this Adapter");
- }
- return null;
- }
- } else if(TypedLiteral.class.isAssignableFrom(value.getClass())){
- try {
- return lf.createObject(type, (TypedLiteral)value);
- } catch (NoConvertorException e) {
- //This usually indicates a missing converter ... so log in warning
- log.warn("unable to convert "+value+" to "+type,e);
- return null;
- } catch (InvalidLiteralTypeException e) {
- //This usually indicated a wrong type of the literal so log in debug
- log.debug("unable to Literal "+value+" to the type"+type,e);
- return null;
- }
- } else {
- //indicates, that someone wants to convert non TypedLiterals to an
- //specific data type
- log.warn("Converting Literals without type information to types other " +
- "String is not supported (requested type: "+type+")! -> return null");
- return null;
- }
- }
+ static Logger log = LoggerFactory.getLogger(LiteralAdapter.class);
+
+ LiteralFactory lf = LiteralFactory.getInstance();
+ RdfValueFactory valueFactory = RdfValueFactory.getInstance();
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public A adapt(T value, Class<A> type) {
+ if(type.equals(String.class)){
+ return (A) value.getLexicalForm();
+ } else if(Text.class.isAssignableFrom(type)){
+ if(value instanceof PlainLiteral ||
+ (value instanceof TypedLiteral &&
+ RdfResourceUtils.STRING_DATATYPES.contains(((TypedLiteral)value).getDataType()))){
+ return (A)valueFactory.createText(value);
+ } else { //this Literal can not be converted to Text!
+ if(value instanceof TypedLiteral){ //TODO: maybe remove this debugging for performance reasons
+ log.debug("TypedLiterals of type "+((TypedLiteral)value).getDataType()+" can not be converted to Text");
+ } else {
+ log.warn("Literal of type"+value.getClass()+" are not supported by this Adapter");
+ }
+ return null;
+ }
+ } else if(TypedLiteral.class.isAssignableFrom(value.getClass())){
+ try {
+ return lf.createObject(type, (TypedLiteral)value);
+ } catch (NoConvertorException e) {
+ //This usually indicates a missing converter ... so log in warning
+ log.warn("unable to convert "+value+" to "+type,e);
+ return null;
+ } catch (InvalidLiteralTypeException e) {
+ //This usually indicated a wrong type of the literal so log in debug
+ log.debug("unable to Literal "+value+" to the type"+type,e);
+ return null;
+ }
+ } else {
+ //indicates, that someone wants to convert non TypedLiterals to an
+ //specific data type
+ log.warn("Converting Literals without type information to types other " +
+ "String is not supported (requested type: "+type+")! -> return null");
+ return null;
+ }
+ }
}
Modified: incubator/stanbol/trunk/rick/model/clerezza/src/main/java/eu/iksproject/rick/model/clerezza/impl/NaturalLanguageLiteralIterator.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/rick/model/clerezza/src/main/java/eu/iksproject/rick/model/clerezza/impl/NaturalLanguageLiteralIterator.java?rev=1044832&r1=1044831&r2=1044832&view=diff
==============================================================================
--- incubator/stanbol/trunk/rick/model/clerezza/src/main/java/eu/iksproject/rick/model/clerezza/impl/NaturalLanguageLiteralIterator.java (original)
+++ incubator/stanbol/trunk/rick/model/clerezza/src/main/java/eu/iksproject/rick/model/clerezza/impl/NaturalLanguageLiteralIterator.java Sun Dec 12 15:13:35 2010
@@ -10,6 +10,7 @@ import org.apache.clerezza.rdf.core.Lite
import org.apache.clerezza.rdf.core.PlainLiteral;
import eu.iksproject.rick.core.utils.AdaptingIterator.Adapter;
+
/**
* TODO: refactor to use the {@link Adapter} interface
* @author Rupert Westenthaler
@@ -17,62 +18,62 @@ import eu.iksproject.rick.core.utils.Ada
*/
public class NaturalLanguageLiteralIterator implements Iterator<Literal> {
- /**
- * Unmodifiable set of the active languages
- */
- protected final Set<String> languages;
- private final boolean containsNull;
- protected final Iterator<Literal> it;
- protected Literal next;
- public NaturalLanguageLiteralIterator(Iterator<Literal> it, String...lang){
- if(it == null){
- throw new IllegalArgumentException("Parameter Iterator<Literal> MUST NOT be NULL!");
- }
- if(lang == null){
- throw new IllegalArgumentException("Parameter languages MUST NOT be NULL!");
- }
- if(lang.length==0){
- throw new IllegalArgumentException("At least one language MUST be present");
- }
- this.it = it;
- this.languages = Collections.unmodifiableSet(new HashSet<String>(Arrays.asList(lang)));
- containsNull = languages.contains(null);
- //init the first element
- next = prepareNext();
- }
- @Override
- public final boolean hasNext() {
- return next != null;
- }
-
- @Override
- public Literal next() {
- Literal current = next;
- next = prepareNext();
- return current;
- }
-
- @Override
- public final void remove() {
- it.remove();
- }
-
- protected final Literal prepareNext(){
- Literal current;
- while(it.hasNext()){
- current = it.next();
- if(current instanceof PlainLiteral){
- if(languages.contains(((PlainLiteral) current).getLanguage())){
- return current;
- } //else wrong language -> filter
- } else if(containsNull){
- /*
- * if the null language is active, than we can also return
- * "normal" literals (with no known language)
- */
- return current;
- } // else no language defined -> filter
- }
- return null; //no more elements -> return null
- }
+ /**
+ * Unmodifiable set of the active languages
+ */
+ protected final Set<String> languages;
+ private final boolean containsNull;
+ protected final Iterator<Literal> it;
+ protected Literal next;
+
+ public NaturalLanguageLiteralIterator(Iterator<Literal> it, String...lang){
+ if(it == null){
+ throw new IllegalArgumentException("Parameter Iterator<Literal> MUST NOT be NULL!");
+ }
+ if(lang == null){
+ throw new IllegalArgumentException("Parameter languages MUST NOT be NULL!");
+ }
+ if(lang.length==0){
+ throw new IllegalArgumentException("At least one language MUST be present");
+ }
+ this.it = it;
+ this.languages = Collections.unmodifiableSet(new HashSet<String>(Arrays.asList(lang)));
+ containsNull = languages.contains(null);
+ //init the first element
+ next = prepareNext();
+ }
+ @Override
+ public final boolean hasNext() {
+ return next != null;
+ }
+
+ @Override
+ public Literal next() {
+ Literal current = next;
+ next = prepareNext();
+ return current;
+ }
+
+ @Override
+ public final void remove() {
+ it.remove();
+ }
+
+ protected final Literal prepareNext(){
+ while (it.hasNext()){
+ Literal current = it.next();
+ if (current instanceof PlainLiteral){
+ if (languages.contains(((PlainLiteral) current).getLanguage())){
+ return current;
+ } //else wrong language -> filter
+ } else if (containsNull){
+ /*
+ * if the null language is active, than we can also return
+ * "normal" literals (with no known language)
+ */
+ return current;
+ } // else no language defined -> filter
+ }
+ return null; //no more elements -> return null
+ }
}
Modified: incubator/stanbol/trunk/rick/model/clerezza/src/main/java/eu/iksproject/rick/model/clerezza/impl/ReferenceIterator.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/rick/model/clerezza/src/main/java/eu/iksproject/rick/model/clerezza/impl/ReferenceIterator.java?rev=1044832&r1=1044831&r2=1044832&view=diff
==============================================================================
--- incubator/stanbol/trunk/rick/model/clerezza/src/main/java/eu/iksproject/rick/model/clerezza/impl/ReferenceIterator.java (original)
+++ incubator/stanbol/trunk/rick/model/clerezza/src/main/java/eu/iksproject/rick/model/clerezza/impl/ReferenceIterator.java Sun Dec 12 15:13:35 2010
@@ -14,28 +14,30 @@ import eu.iksproject.rick.servicesapi.mo
*/
public class ReferenceIterator implements Iterator<Reference> {
- private final RdfValueFactory valueFactory = RdfValueFactory.getInstance();
- private final Iterator<UriRef> it;
- public ReferenceIterator(Iterator<UriRef> it){
- if(it == null){
- throw new IllegalArgumentException("The parent Iterator<UriRef> MUST NOT be NULL");
- }
- this.it = it;
- }
- @Override
- public boolean hasNext() {
- return it.hasNext();
- }
-
- @Override
- public Reference next() {
- UriRef next = it.next();
- return next!=null?valueFactory.createReference(next):null;
- }
-
- @Override
- public void remove() {
- it.remove();
- }
+ private final RdfValueFactory valueFactory = RdfValueFactory.getInstance();
+ private final Iterator<UriRef> it;
+
+ public ReferenceIterator(Iterator<UriRef> it){
+ if(it == null){
+ throw new IllegalArgumentException("The parent Iterator<UriRef> MUST NOT be NULL");
+ }
+ this.it = it;
+ }
+
+ @Override
+ public boolean hasNext() {
+ return it.hasNext();
+ }
+
+ @Override
+ public Reference next() {
+ UriRef next = it.next();
+ return next!=null?valueFactory.createReference(next):null;
+ }
+
+ @Override
+ public void remove() {
+ it.remove();
+ }
}
Modified: incubator/stanbol/trunk/rick/model/clerezza/src/main/java/eu/iksproject/rick/model/clerezza/impl/Resource2ValueAdapter.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/rick/model/clerezza/src/main/java/eu/iksproject/rick/model/clerezza/impl/Resource2ValueAdapter.java?rev=1044832&r1=1044831&r2=1044832&view=diff
==============================================================================
--- incubator/stanbol/trunk/rick/model/clerezza/src/main/java/eu/iksproject/rick/model/clerezza/impl/Resource2ValueAdapter.java (original)
+++ incubator/stanbol/trunk/rick/model/clerezza/src/main/java/eu/iksproject/rick/model/clerezza/impl/Resource2ValueAdapter.java Sun Dec 12 15:13:35 2010
@@ -22,52 +22,54 @@ import eu.iksproject.rick.servicesapi.mo
* @param <T> the type of the Resource that can be converted to values
*/
public class Resource2ValueAdapter<T extends Resource> implements Adapter<T, Object> {
-
- Logger log = LoggerFactory.getLogger(Resource2ValueAdapter.class);
-
-
- protected final LiteralFactory literalFactory = LiteralFactory.getInstance();
-
- RdfValueFactory valueFactory = RdfValueFactory.getInstance();
- @Override
- public Object adapt(T value, Class<Object> type) {
- if(value instanceof UriRef){
- return valueFactory.createReference((UriRef)value);
- } else if(value instanceof PlainLiteral){
- return valueFactory.createText((Literal)value);
- } else if(value instanceof TypedLiteral){
- TypedLiteral literal = (TypedLiteral) value;
- if(literal.getDataType() == null){ //if no dataType is defined
- //return a Text without a language
- return valueFactory.createText(literal);
- } else {
- XsdDataTypeEnum mapping = RdfResourceUtils.XSD_DATATYPE_VALUE_MAPPING.get(literal.getDataType());
- if(mapping != null){
- if(mapping.getMappedClass() != null){
- return literalFactory.createObject(mapping.getMappedClass(), literal);
- } else { //if no mapped class
- //bypass the LiteralFactory and return the string representation
- return literal.getLexicalForm();
- }
- } else { //if dataType is not supported
- /*
- * this could indicate two things:
- * 1) the SimpleLiteralFactory supports a new DataType and
- * because of that it creates Literals with this Type
- * 2) Literals with this data type where created by other
- * applications.
- * In the first case one need to update the enumeration. In
- * the second case using the LexicalForm should be OK
- * Rupert Westenthaler 2010.10.28
- */
- log.warn("Missing Mapping for DataType "+literal.getDataType().getUnicodeString()+" -> return String representation");
- return literal.getLexicalForm();
- }
- }
- } else {
- log.warn("Unsupported Resource Type "+value.getClass()+" -> return String by using the toString method");
- return value.toString();
- }
- }
+
+ Logger log = LoggerFactory.getLogger(Resource2ValueAdapter.class);
+
+
+ protected final LiteralFactory literalFactory = LiteralFactory.getInstance();
+
+ RdfValueFactory valueFactory = RdfValueFactory.getInstance();
+
+ @Override
+ public Object adapt(T value, Class<Object> type) {
+ if(value instanceof UriRef){
+ return valueFactory.createReference((UriRef)value);
+ } else if(value instanceof PlainLiteral){
+ return valueFactory.createText((Literal)value);
+ } else if(value instanceof TypedLiteral){
+ TypedLiteral literal = (TypedLiteral) value;
+ if(literal.getDataType() == null){ //if no dataType is defined
+ //return a Text without a language
+ return valueFactory.createText(literal);
+ } else {
+ XsdDataTypeEnum mapping = RdfResourceUtils.XSD_DATATYPE_VALUE_MAPPING.get(literal.getDataType());
+ if(mapping != null){
+ if(mapping.getMappedClass() != null){
+ return literalFactory.createObject(mapping.getMappedClass(), literal);
+ } else { //if no mapped class
+ //bypass the LiteralFactory and return the string representation
+ return literal.getLexicalForm();
+ }
+ } else { //if dataType is not supported
+ /*
+ * this could indicate two things:
+ * 1) the SimpleLiteralFactory supports a new DataType and
+ * because of that it creates Literals with this Type
+ * 2) Literals with this data type where created by other
+ * applications.
+ * In the first case one need to update the enumeration. In
+ * the second case using the LexicalForm should be OK
+ * Rupert Westenthaler 2010.10.28
+ */
+ log.warn("Missing Mapping for DataType "+literal.getDataType().getUnicodeString()
+ +" -> return String representation");
+ return literal.getLexicalForm();
+ }
+ }
+ } else {
+ log.warn("Unsupported Resource Type "+value.getClass()+" -> return String by using the toString method");
+ return value.toString();
+ }
+ }
}
Modified: incubator/stanbol/trunk/rick/model/clerezza/src/main/java/eu/iksproject/rick/model/clerezza/impl/UriRefAdapter.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/rick/model/clerezza/src/main/java/eu/iksproject/rick/model/clerezza/impl/UriRefAdapter.java?rev=1044832&r1=1044831&r2=1044832&view=diff
==============================================================================
--- incubator/stanbol/trunk/rick/model/clerezza/src/main/java/eu/iksproject/rick/model/clerezza/impl/UriRefAdapter.java (original)
+++ incubator/stanbol/trunk/rick/model/clerezza/src/main/java/eu/iksproject/rick/model/clerezza/impl/UriRefAdapter.java Sun Dec 12 15:13:35 2010
@@ -13,32 +13,32 @@ import eu.iksproject.rick.core.utils.Ada
public class UriRefAdapter<A> implements Adapter<UriRef, A> {
- static Logger log = LoggerFactory.getLogger(UriRefAdapter.class);
+ static Logger log = LoggerFactory.getLogger(UriRefAdapter.class);
- @SuppressWarnings("unchecked")
- @Override
- public A adapt(UriRef value, Class<A> type) {
- if(type.equals(URI.class)){
- try {
- return (A) new URI(value.getUnicodeString());
- } catch (URISyntaxException e) {
- log.warn("Unable to parse an URI for UriRef "+value,e);
- return null;
- }
- } else if(type.equals(URL.class)){
- try {
- return (A) new URL(value.getUnicodeString());
- } catch (MalformedURLException e) {
- log.warn("Unable to parse an URL for UriRef "+value,e);
- }
- } else if(type.equals(String.class)){
- return (A) value.getUnicodeString();
- } else if(type.equals(UriRef.class)){ //Who converts UriRef -> UriRef ^
- return (A) value;
- } else {
- log.warn(type+" is not a supported target type for "+UriRef.class);
- }
- return null;
- }
+ @SuppressWarnings("unchecked")
+ @Override
+ public A adapt(UriRef value, Class<A> type) {
+ if(type.equals(URI.class)){
+ try {
+ return (A) new URI(value.getUnicodeString());
+ } catch (URISyntaxException e) {
+ log.warn("Unable to parse an URI for UriRef "+value,e);
+ return null;
+ }
+ } else if(type.equals(URL.class)){
+ try {
+ return (A) new URL(value.getUnicodeString());
+ } catch (MalformedURLException e) {
+ log.warn("Unable to parse an URL for UriRef "+value,e);
+ }
+ } else if(type.equals(String.class)){
+ return (A) value.getUnicodeString();
+ } else if(type.equals(UriRef.class)){ //Who converts UriRef -> UriRef ^
+ return (A) value;
+ } else {
+ log.warn(type+" is not a supported target type for "+UriRef.class);
+ }
+ return null;
+ }
}
Modified: incubator/stanbol/trunk/rick/model/clerezza/src/main/java/eu/iksproject/rick/model/clerezza/utils/Resource2StringAdapter.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/rick/model/clerezza/src/main/java/eu/iksproject/rick/model/clerezza/utils/Resource2StringAdapter.java?rev=1044832&r1=1044831&r2=1044832&view=diff
==============================================================================
--- incubator/stanbol/trunk/rick/model/clerezza/src/main/java/eu/iksproject/rick/model/clerezza/utils/Resource2StringAdapter.java (original)
+++ incubator/stanbol/trunk/rick/model/clerezza/src/main/java/eu/iksproject/rick/model/clerezza/utils/Resource2StringAdapter.java Sun Dec 12 15:13:35 2010
@@ -8,24 +8,24 @@ import eu.iksproject.rick.core.utils.Ada
/**
* Needed because UriRefs and Literals use the RDF representation for the
* toString Method
- *
+ *
* @author Rupert Westenthaler
*
* @param <T>
*/
public class Resource2StringAdapter<T extends Resource> implements Adapter<T, String> {
- @Override
- public String adapt(T value, Class<String> type) {
- if(value == null){
- return null;
- } else if(value instanceof UriRef){
- return ((UriRef)value).getUnicodeString();
- } else if(value instanceof Literal){
- return ((Literal)value).getLexicalForm();
- } else {
- return value.toString();
- }
- }
+ @Override
+ public String adapt(T value, Class<String> type) {
+ if (value == null) {
+ return null;
+ } else if (value instanceof UriRef) {
+ return ((UriRef) value).getUnicodeString();
+ } else if (value instanceof Literal) {
+ return ((Literal) value).getLexicalForm();
+ } else {
+ return value.toString();
+ }
+ }
}
Modified: incubator/stanbol/trunk/rick/query/clerezza/src/main/java/eu/iksproject/rick/query/clerezza/RdfQueryResultList.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/rick/query/clerezza/src/main/java/eu/iksproject/rick/query/clerezza/RdfQueryResultList.java?rev=1044832&r1=1044831&r2=1044832&view=diff
==============================================================================
--- incubator/stanbol/trunk/rick/query/clerezza/src/main/java/eu/iksproject/rick/query/clerezza/RdfQueryResultList.java (original)
+++ incubator/stanbol/trunk/rick/query/clerezza/src/main/java/eu/iksproject/rick/query/clerezza/RdfQueryResultList.java Sun Dec 12 15:13:35 2010
@@ -15,65 +15,65 @@ import eu.iksproject.rick.servicesapi.qu
public class RdfQueryResultList implements QueryResultList<Representation> {
- private final FieldQuery query;
- private final Collection<RdfRepresentation> results;
- private final MGraph resultGraph;
-
- public RdfQueryResultList(FieldQuery query,MGraph resultGraph) {
- if(query == null){
- throw new IllegalArgumentException("Parameter Query MUST NOT be NULL!");
- }
- if(resultGraph == null){
- throw new IllegalArgumentException("Parameter \"MGraph resultGraph\" MUST NOT be NULL");
- }
- this.query = query;
- this.resultGraph = resultGraph;
- this.results = Collections.unmodifiableCollection(
- ModelUtils.asCollection(
- SparqlQueryUtils.parseQueryResultsFromMGraph(resultGraph)));
- }
- @Override
- public FieldQuery getQuery() {
- return query;
- }
-
- @Override
- public Set<String> getSelectedFields() {
- return query.getSelectedFields();
- }
-
- @Override
- public boolean isEmpty() {
- return results.isEmpty();
- }
-
- @Override
- public Iterator<Representation> iterator() {
- return new Iterator<Representation>() {
- Iterator<RdfRepresentation> it = results.iterator();
- @Override
- public boolean hasNext() { return it.hasNext(); }
- @Override
- public Representation next() { return it.next(); }
- @Override
- public void remove() { it.remove(); }
- };
- }
-
- @Override
- public int size() {
- return results.size();
- }
- /**
- * Getter for the RDF Graph holding the Results of the Query
- * @return the RDF Graph with the Results
- */
- public MGraph getResultGraph() {
- return resultGraph;
- }
- @Override
- public Class<Representation> getType() {
- return Representation.class;
- }
+ private final FieldQuery query;
+ private final Collection<RdfRepresentation> results;
+ private final MGraph resultGraph;
+
+ public RdfQueryResultList(FieldQuery query,MGraph resultGraph) {
+ if(query == null){
+ throw new IllegalArgumentException("Parameter Query MUST NOT be NULL!");
+ }
+ if(resultGraph == null){
+ throw new IllegalArgumentException("Parameter \"MGraph resultGraph\" MUST NOT be NULL");
+ }
+ this.query = query;
+ this.resultGraph = resultGraph;
+ this.results = Collections.unmodifiableCollection(
+ ModelUtils.asCollection(
+ SparqlQueryUtils.parseQueryResultsFromMGraph(resultGraph)));
+ }
+ @Override
+ public FieldQuery getQuery() {
+ return query;
+ }
+
+ @Override
+ public Set<String> getSelectedFields() {
+ return query.getSelectedFields();
+ }
+
+ @Override
+ public boolean isEmpty() {
+ return results.isEmpty();
+ }
+
+ @Override
+ public Iterator<Representation> iterator() {
+ return new Iterator<Representation>() {
+ Iterator<RdfRepresentation> it = results.iterator();
+ @Override
+ public boolean hasNext() { return it.hasNext(); }
+ @Override
+ public Representation next() { return it.next(); }
+ @Override
+ public void remove() { it.remove(); }
+ };
+ }
+
+ @Override
+ public int size() {
+ return results.size();
+ }
+ /**
+ * Getter for the RDF Graph holding the Results of the Query
+ * @return the RDF Graph with the Results
+ */
+ public MGraph getResultGraph() {
+ return resultGraph;
+ }
+ @Override
+ public Class<Representation> getType() {
+ return Representation.class;
+ }
}
Modified: incubator/stanbol/trunk/rick/query/clerezza/src/main/java/eu/iksproject/rick/query/clerezza/SparqlFieldQuery.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/rick/query/clerezza/src/main/java/eu/iksproject/rick/query/clerezza/SparqlFieldQuery.java?rev=1044832&r1=1044831&r2=1044832&view=diff
==============================================================================
--- incubator/stanbol/trunk/rick/query/clerezza/src/main/java/eu/iksproject/rick/query/clerezza/SparqlFieldQuery.java (original)
+++ incubator/stanbol/trunk/rick/query/clerezza/src/main/java/eu/iksproject/rick/query/clerezza/SparqlFieldQuery.java Sun Dec 12 15:13:35 2010
@@ -14,145 +14,145 @@ import eu.iksproject.rick.servicesapi.qu
*
*/
public class SparqlFieldQuery extends FieldQueryImpl implements FieldQuery ,Cloneable {
- /**
- * String used as prefix for variables generated for fields
- */
- private static final String FIELD_VAR_PREFIX = "v_";
- private static final String ROOT_VAR_NAME = "id";
- private int varNum;
- protected final Map<String,String> field2VarMappings;
- private final Map<String, String> unmodField2VarMappings;
- protected EndpointTypeEnum endpointType;
- protected SparqlFieldQuery() {
- this(null);
- }
- protected SparqlFieldQuery(EndpointTypeEnum endpointType){
- super();
- this.endpointType = endpointType != null?endpointType:EndpointTypeEnum.Standard;
- varNum = 0;
- field2VarMappings = new HashMap<String, String>();
- unmodField2VarMappings = Collections.unmodifiableMap(field2VarMappings);
- }
- public final EndpointTypeEnum getEndpointType() {
- return endpointType;
- }
-
- public final void setEndpointType(EndpointTypeEnum endpointType) {
- this.endpointType = endpointType;
- }
- /*
- * (non-Javadoc)
- * @see eu.iksproject.rick.core.query.FieldQueryImpl#addSelectedField(java.lang.String)
- */
- @Override
- public void addSelectedField(String field) {
- super.addSelectedField(field);
- field2VarMappings.put(field, getFieldVar());
- }
- /*
- * (non-Javadoc)
- * @see eu.iksproject.rick.core.query.FieldQueryImpl#addSelectedFields(java.util.Collection)
- */
- @Override
- public void addSelectedFields(Collection<String> fields) {
- super.addSelectedFields(fields);
- for(String field : fields){
- field2VarMappings.put(field, getFieldVar());
- }
- }
- /*
- * (non-Javadoc)
- * @see eu.iksproject.rick.core.query.FieldQueryImpl#removeSelectedField(java.lang.String)
- */
- @Override
- public void removeSelectedField(String field) {
- super.removeSelectedField(field);
- field2VarMappings.remove(field);
- }
- /*
- * (non-Javadoc)
- * @see eu.iksproject.rick.core.query.FieldQueryImpl#removeSelectedFields(java.util.Collection)
- */
- @Override
- public void removeSelectedFields(Collection<String> fields) {
- super.removeSelectedFields(fields);
- for(String field : fields){
- field2VarMappings.remove(field);
- }
- }
- /**
- * Getter for the variable name for a selected field
- * @param field the selected field
- * @return the variable name or <code>null</code> if the parsed field is not selected.
- */
- public String getVariableName(String field){
- return field2VarMappings.get(field);
- }
- /**
- * Getter for the unmodifiable field name to variable name mapping.
- * @return
- */
- public Map<String,String> getFieldVariableMappings(){
- return unmodField2VarMappings;
- }
- private String getFieldVar(){
- varNum++;
- return FIELD_VAR_PREFIX+varNum;
- }
- public String getRootVariableName(){
- return ROOT_VAR_NAME;
- }
- /**
- * Clones the query (including the field to var name mapping)
- */
- @Override
- public SparqlFieldQuery clone() {
- SparqlFieldQuery clone = super.copyTo(new SparqlFieldQuery());
- //Note: this uses the public API. However the field->ar mapping might still
- //be different if any removeSelectedField(..) method was used on this
- //instance. Because of that manually set the map and the value of the int.
- //clone.field2VarMappings.clear(); //clear is not necessary, because the keys are equals!
- clone.field2VarMappings.putAll(field2VarMappings);
- clone.varNum = varNum;
- return clone;
- }
- @Override
- public int hashCode() {
- return super.hashCode();
- }
+ /**
+ * String used as prefix for variables generated for fields
+ */
+ private static final String FIELD_VAR_PREFIX = "v_";
+ private static final String ROOT_VAR_NAME = "id";
+ private int varNum;
+ protected final Map<String,String> field2VarMappings;
+ private final Map<String, String> unmodField2VarMappings;
+ protected EndpointTypeEnum endpointType;
+ protected SparqlFieldQuery() {
+ this(null);
+ }
+ protected SparqlFieldQuery(EndpointTypeEnum endpointType){
+ super();
+ this.endpointType = endpointType != null?endpointType:EndpointTypeEnum.Standard;
+ varNum = 0;
+ field2VarMappings = new HashMap<String, String>();
+ unmodField2VarMappings = Collections.unmodifiableMap(field2VarMappings);
+ }
+ public final EndpointTypeEnum getEndpointType() {
+ return endpointType;
+ }
- /**
- * Removes also the field to var name mappings
- * @see eu.iksproject.rick.core.query.FieldQueryImpl#removeAllSelectedFields()
- */
- @Override
- public void removeAllSelectedFields() {
- super.removeAllSelectedFields();
- field2VarMappings.clear();
- varNum = 0;
- }
- @Override
- public boolean equals(Object obj) {
- return super.equals(obj) && obj instanceof SparqlFieldQuery &&
- ((SparqlFieldQuery)obj).field2VarMappings.equals(field2VarMappings) &&
- ((SparqlFieldQuery)obj).varNum == varNum;
- }
- /**
- * Getter for the SPARQL SELECT representation of this FieldQuery
- * @return the SPARQL SELECT query
- */
- public String toSparqlSelect(boolean includeFields){
- return SparqlQueryUtils.createSparqlSelectQuery(this,includeFields,endpointType);
- }
- /**
- * Getter for the SPARQL CONSTRUCT representation of this FieldQuery
- * @return the SPARQL CONSTRUCT query
- */
- public String toSparqlConstruct(){
- return SparqlQueryUtils.createSparqlConstructQuery(this,endpointType);
- }
- @Override
- public String toString() {
- return super.toString()+" field->variable mappings: "+field2VarMappings;
- }
+ public final void setEndpointType(EndpointTypeEnum endpointType) {
+ this.endpointType = endpointType;
+ }
+ /*
+ * (non-Javadoc)
+ * @see eu.iksproject.rick.core.query.FieldQueryImpl#addSelectedField(java.lang.String)
+ */
+ @Override
+ public void addSelectedField(String field) {
+ super.addSelectedField(field);
+ field2VarMappings.put(field, getFieldVar());
+ }
+ /*
+ * (non-Javadoc)
+ * @see eu.iksproject.rick.core.query.FieldQueryImpl#addSelectedFields(java.util.Collection)
+ */
+ @Override
+ public void addSelectedFields(Collection<String> fields) {
+ super.addSelectedFields(fields);
+ for(String field : fields){
+ field2VarMappings.put(field, getFieldVar());
+ }
+ }
+ /*
+ * (non-Javadoc)
+ * @see eu.iksproject.rick.core.query.FieldQueryImpl#removeSelectedField(java.lang.String)
+ */
+ @Override
+ public void removeSelectedField(String field) {
+ super.removeSelectedField(field);
+ field2VarMappings.remove(field);
+ }
+ /*
+ * (non-Javadoc)
+ * @see eu.iksproject.rick.core.query.FieldQueryImpl#removeSelectedFields(java.util.Collection)
+ */
+ @Override
+ public void removeSelectedFields(Collection<String> fields) {
+ super.removeSelectedFields(fields);
+ for(String field : fields){
+ field2VarMappings.remove(field);
+ }
+ }
+ /**
+ * Getter for the variable name for a selected field
+ * @param field the selected field
+ * @return the variable name or <code>null</code> if the parsed field is not selected.
+ */
+ public String getVariableName(String field){
+ return field2VarMappings.get(field);
+ }
+ /**
+ * Getter for the unmodifiable field name to variable name mapping.
+ * @return
+ */
+ public Map<String,String> getFieldVariableMappings(){
+ return unmodField2VarMappings;
+ }
+ private String getFieldVar(){
+ varNum++;
+ return FIELD_VAR_PREFIX+varNum;
+ }
+ public String getRootVariableName(){
+ return ROOT_VAR_NAME;
+ }
+ /**
+ * Clones the query (including the field to var name mapping)
+ */
+ @Override
+ public SparqlFieldQuery clone() {
+ SparqlFieldQuery clone = super.copyTo(new SparqlFieldQuery());
+ //Note: this uses the public API. However the field->ar mapping might still
+ //be different if any removeSelectedField(..) method was used on this
+ //instance. Because of that manually set the map and the value of the int.
+ //clone.field2VarMappings.clear(); //clear is not necessary, because the keys are equals!
+ clone.field2VarMappings.putAll(field2VarMappings);
+ clone.varNum = varNum;
+ return clone;
+ }
+ @Override
+ public int hashCode() {
+ return super.hashCode();
+ }
+
+ /**
+ * Removes also the field to var name mappings
+ * @see eu.iksproject.rick.core.query.FieldQueryImpl#removeAllSelectedFields()
+ */
+ @Override
+ public void removeAllSelectedFields() {
+ super.removeAllSelectedFields();
+ field2VarMappings.clear();
+ varNum = 0;
+ }
+ @Override
+ public boolean equals(Object obj) {
+ return super.equals(obj) && obj instanceof SparqlFieldQuery &&
+ ((SparqlFieldQuery)obj).field2VarMappings.equals(field2VarMappings) &&
+ ((SparqlFieldQuery)obj).varNum == varNum;
+ }
+ /**
+ * Getter for the SPARQL SELECT representation of this FieldQuery
+ * @return the SPARQL SELECT query
+ */
+ public String toSparqlSelect(boolean includeFields){
+ return SparqlQueryUtils.createSparqlSelectQuery(this,includeFields,endpointType);
+ }
+ /**
+ * Getter for the SPARQL CONSTRUCT representation of this FieldQuery
+ * @return the SPARQL CONSTRUCT query
+ */
+ public String toSparqlConstruct(){
+ return SparqlQueryUtils.createSparqlConstructQuery(this,endpointType);
+ }
+ @Override
+ public String toString() {
+ return super.toString()+" field->variable mappings: "+field2VarMappings;
+ }
}
Modified: incubator/stanbol/trunk/rick/query/clerezza/src/main/java/eu/iksproject/rick/query/clerezza/SparqlFieldQueryFactory.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/rick/query/clerezza/src/main/java/eu/iksproject/rick/query/clerezza/SparqlFieldQueryFactory.java?rev=1044832&r1=1044831&r2=1044832&view=diff
==============================================================================
--- incubator/stanbol/trunk/rick/query/clerezza/src/main/java/eu/iksproject/rick/query/clerezza/SparqlFieldQueryFactory.java (original)
+++ incubator/stanbol/trunk/rick/query/clerezza/src/main/java/eu/iksproject/rick/query/clerezza/SparqlFieldQueryFactory.java Sun Dec 12 15:13:35 2010
@@ -5,34 +5,34 @@ import eu.iksproject.rick.servicesapi.qu
public final class SparqlFieldQueryFactory implements FieldQueryFactory {
- private static SparqlFieldQueryFactory instance;
-
- public static SparqlFieldQueryFactory getInstance(){
- if(instance == null){
- instance = new SparqlFieldQueryFactory();
- }
- return instance;
- }
- private SparqlFieldQueryFactory(){
- super();
- }
- @Override
- public SparqlFieldQuery createFieldQuery() {
- return new SparqlFieldQuery();
- }
- /**
- * Utility Method to create an {@link SparqlFieldQuery} based on the parse {@link FieldQuery}
+ private static SparqlFieldQueryFactory instance;
+
+ public static SparqlFieldQueryFactory getInstance(){
+ if(instance == null){
+ instance = new SparqlFieldQueryFactory();
+ }
+ return instance;
+ }
+ private SparqlFieldQueryFactory(){
+ super();
+ }
+ @Override
+ public SparqlFieldQuery createFieldQuery() {
+ return new SparqlFieldQuery();
+ }
+ /**
+ * Utility Method to create an {@link SparqlFieldQuery} based on the parse {@link FieldQuery}
* @param parsedQuery the parsed Query
- */
- public static SparqlFieldQuery getSparqlFieldQuery(FieldQuery parsedQuery) {
- if(parsedQuery == null){
- return null;
- } else if(parsedQuery instanceof SparqlFieldQuery){
- return (SparqlFieldQuery)parsedQuery;
- } else {
- return parsedQuery.copyTo(new SparqlFieldQuery());
- }
- }
+ */
+ public static SparqlFieldQuery getSparqlFieldQuery(FieldQuery parsedQuery) {
+ if(parsedQuery == null){
+ return null;
+ } else if(parsedQuery instanceof SparqlFieldQuery){
+ return (SparqlFieldQuery)parsedQuery;
+ } else {
+ return parsedQuery.copyTo(new SparqlFieldQuery());
+ }
+ }
}