You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stanbol.apache.org by rw...@apache.org on 2011/01/14 12:39:27 UTC

svn commit: r1058959 [3/4] - in /incubator/stanbol/trunk/rick: ./ generic/core/ generic/core/src/main/java/eu/iksproject/rick/core/model/ generic/core/src/main/java/eu/iksproject/rick/core/site/ generic/core/src/main/java/eu/iksproject/rick/core/utils/...

Modified: incubator/stanbol/trunk/rick/indexing/genericRdf/src/main/java/eu/iksproject/rick/indexing/rdf/RdfIndexer.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/rick/indexing/genericRdf/src/main/java/eu/iksproject/rick/indexing/rdf/RdfIndexer.java?rev=1058959&r1=1058958&r2=1058959&view=diff
==============================================================================
--- incubator/stanbol/trunk/rick/indexing/genericRdf/src/main/java/eu/iksproject/rick/indexing/rdf/RdfIndexer.java (original)
+++ incubator/stanbol/trunk/rick/indexing/genericRdf/src/main/java/eu/iksproject/rick/indexing/rdf/RdfIndexer.java Fri Jan 14 11:39:26 2011
@@ -130,7 +130,7 @@ public class RdfIndexer {
      * @author Rupert Westenthaler
      *
      */
-    public static enum IndexingMode{ REPLACE, APPEND }
+    public static enum IndexingMode{ NORMAL, RANKING_MAP_BASED }
 
     public static final String RDF_XML = "application/rdf+xml";
     public static final String TURTLE = "text/turtle";
@@ -192,299 +192,282 @@ public class RdfIndexer {
      * The {@link Object#toString()} method is used on elements to get the actual type!
      */
     public static final String KEY_RDF_TYPES = "eu.iksproject.rick.indexing.rdf.indexedTypes";
-    /**
-     * Key used to parse the indexing mode. Values should be of instance {@link IndexingMode}
-     * or the {@link Object#toString()} value should be a member of this enum!
-     */
-    public static final String KEY_INDEXING_MODE = "eu.iksproject.rick.indexing.rdf.indexingMode";
-    /**
-     * If <code>true</code> than no RDF data are loaded. Instead it is assumed, that
-     * the Graph of the parsed {@link #KEY_MODEL_NAME} already contains all the needed
-     * data!<p>
-     * This can be useful if one first wants to index rdf:type A and than rdf:type B
-     * based on the same set of data
-     */
-    public static final String KEY_SKIP_READ = "eu.iksproject.rick.indexing.rdf.skipRead";
-    /**
-     * The number of {@link Representation}s stored at once in the SolrYard!
-     */
-    public static final String KEY_CHUNK_SIZE = "eu.iksproject.rick.indexing.rdf.chunkSize";
-    /**
-     * Can be used to parse a map with {@link String} entity id, {@link Float} rank
-     * for entities.<p>
-     * Such values are added to Representations for the {@link RdfResourceEnum#signRank}
-     * field.
-     */
-    public static final String KEY_ENTITY_RANKINGS = "eu.iksproject.rick.indexing.rdf.entityRankings";
-    /**
-     * Can be used to activate ignoring of Entities without a page rank
-     */
-    public static final String KEY_IGNORE_ENTITIES_WITHOUT_ENTITY_RANKING = "eu.iksproject.rick.indexing.rdf.ignoreEntitiesWithoutRankings";
-    /**
-     * If set to a value >= 0 this is used to exclude Entities with a lower or
-     * missing entity rank
-     */
-    public static final String KEY_REQUIRED_ENTITY_RANKING = "eu.iksproject.rick.indexing.rdf.requiredRanking";
-    /**
-     * The rank for entities with a missing rank. This takes only effect if
-     * {@link #KEY_IGNORE_ENTITIES_WITHOUT_ENTITY_RANKING} is set to <code>false</code>
-     * (the default)
-     */
-    public static final String KEY_DEFAULT_ENTITY_RANKING = "eu.iksproject.rick.indexing.rdf.defaultRanking";
-    /**
-     * Expert only: This allows to enable indexing based on the keys in the map parsed with the
-     * entity rankings. This will only index entities that are keys in that map.
-     * If no Map is parsed by {@link #KEY_ENTITY_RANKINGS}, than activating this mode
-     * will not be successful and a warning will be written.<p>
-     * This mode is about 50% slower than the usual indexing mode. Therefore this
-     * mode makes only sense id less than 50% of the entities are indexed.
-     */
-    public static final String KEY_ENTITY_RANKING_BASED_INDEXING_MODE = "eu.iksproject.rick.indexing.rdf.rankingBasedIndexingMode";
-    /**
-     * The resume Mode first checks if a Resource is already present in the parsed
-     * Yard. If this is the case, than the representation is not indexes again.<p>
-     * This mode is intended to resume indexing after stopping a previous call before
-     * finished. The default value = false.
-     */
-    public static final String KEY_RESUME_MODE = "eu.iksproject.rick.indexing.rdf.resumeMode";
-
-    private final IndexingMode indexingMode;
-    private final Yard yard;
-    private final ValueFactory vf;
-    private final List<File> rdfFiles;
-    private final File indexingDir;
-    private final String modelName;
-//    private final ParsingProvider parser = new JenaParserProvider();
-    //private final WeightedTcProvider provider;
-    private final FieldMapper mapper;
-    private final Set<String> types;
-    //private MGraph indexingGraph;
-    private final DatasetGraphTDB indexingDataset;
-    private final boolean skipRead;
-    private Location modelLocation;
-    private int indexingChunkSize = 1000;
-
-    //vars for entity rankings
-    private Map<String,Float> entityRankings = null;
-    private boolean ignoreEntitiesWithoutRank = false;
-    private float defaultEntityRanking = -1;
-    private String entityRankingField = RdfResourceEnum.signRank.getUri();
-    private float minimumRequiredEntityRanking = -1;
-    private boolean rankingMode;
-    private boolean resumeMode;
-
-
-    public RdfIndexer(Dictionary<String, Object> config){
-        this.yard = (Yard)config.get(KEY_YARD);
-        if(yard == null){
-            throw new IllegalArgumentException("Parsed config MUST CONTAIN a Yard. Use the key "+KEY_YARD+" to parse the YardInstance used to store the geonames.org index!");
-        } else {
-            log.info(String.format("Using Yard %s (id=%s) to index parsed RDF data",
-                    yard.getName(),yard.getId()));
-        }
-        this.vf = yard.getValueFactory();
-        Object rdfFiles = config.get(KEY_RDF_FILES);
-        if(rdfFiles instanceof Iterable<?>){
-            this.rdfFiles = new ArrayList<File>();
-            for(Object value : (Iterable<?>)rdfFiles){
-                this.rdfFiles.add(checkFile(value.toString()));
-            }
-        } else {
-            this.rdfFiles = Collections.singletonList(checkFile(rdfFiles.toString()));
-        }
-        Object indexingDir = config.get(KEY_RDF_STORE_DIR);
-        if(indexingDir == null){
-            indexingDir = "indexingData";
-            config.put(KEY_RDF_STORE_DIR, indexingDir);
-        }
-        this.indexingDir = checkFile(indexingDir.toString(), false, true);
-        Object modelName = config.get(KEY_MODEL_NAME);
-        if(modelName == null){
-            modelName = "indexingModel-"+ModelUtils.randomUUID().toString();
-            config.put(KEY_MODEL_NAME, modelName);
-        }
-        this.modelName = modelName.toString();
-        //init the types!
-        Iterable<?> types = (Iterable<?>)config.get(KEY_RDF_TYPES);
-        if(types != null){
-            Set<String> typeSet = new HashSet<String>();
-            for(Object type : types){
-                if(type != null){
-                    typeSet.add(type.toString());
-                    log.info("  - adding Resoures with rdf:type "+type);
-                }
-            }
-            if(typeSet.isEmpty()){
-                log.info("  - adding all Types (no rdf:type based restriction for RDF Reseource present)");
-                this.types = null;
-            } else {
-                this.types = typeSet;
-            }
-        } else{
-            log.info("  - adding all Types (no rdf:type based restriction for RDF Reseource present)");
-            this.types = null; //null or an iterable with one or more elements!
-        }
-        //init the indexing mode
-        Object indexingMode = config.get(KEY_INDEXING_MODE);
-        if(indexingMode == null){
-            this.indexingMode = IndexingMode.REPLACE; //default to replace
-        } else if(indexingMode instanceof IndexingMode){
-            this.indexingMode = (IndexingMode)indexingMode;
-        } else {
-            try {
-                this.indexingMode = IndexingMode.valueOf(indexingMode.toString());
-            }catch (IllegalArgumentException e) {
-                //catch and re-throw with a better message!
-                throw new IllegalArgumentException(
-                        String.format("Values of KEY \"%s\" MUST BE of Type %s or the toString() value MUST BE a member of this Enumeration. If the Key is missing %s is used!",
-                                KEY_INDEXING_MODE,IndexingMode.class,IndexingMode.REPLACE),e);
-            }
-        }
-        //init the fieldMapper
-        Iterable<?> mappings = (Iterable<?>)config.get(KEY_FIELD_MAPPINGS);
-        List<FieldMapping> fieldMappings;
-        if(mappings != null){
-            fieldMappings = new ArrayList<FieldMapping>();
-            for(Object mappingString : mappings){
-                if(mappingString != null){
-                    FieldMapping fieldMapping = FieldMappingUtils.parseFieldMapping(mappingString.toString());
-                    if(fieldMapping != null){
-                        fieldMappings.add(fieldMapping);
-                    }
-                }
-            }
-            if(!fieldMappings.isEmpty()){
-                this.mapper = new DefaultFieldMapperImpl(ValueConverterFactory.getInstance(vf));
-                for(FieldMapping mapping : fieldMappings){
-                    mapper.addMapping(mapping);
-                }
-                //we need to add a mapping for the field rankings (if a mapper is present)
-                mapper.addMapping(new FieldMapping(this.entityRankingField));
-            } else {
-                this.mapper = null;
-            }
-        } else {
-            this.mapper = null;
-        }
-        File modelDir = new File(this.indexingDir,this.modelName);
-        if(!modelDir.exists()){
-            modelDir.mkdir();
-        } else if(!modelDir.isDirectory()){
-            throw new IllegalStateException(String.format("A directory for %s already exists but is not a directory!",modelDir.getAbsoluteFile()));
-        } //else exists and is a dir -> nothing to do
-        Object skipRead = config.get(KEY_SKIP_READ);
-        if(skipRead != null){
-            if(skipRead instanceof Boolean){
-                this.skipRead = ((Boolean)skipRead).booleanValue();
-            } else {
-                this.skipRead = Boolean.parseBoolean(skipRead.toString());
-            }
-        } else {
-            this.skipRead = false;
-        }
-        Integer chunkSize = (Integer)config.get(KEY_CHUNK_SIZE);
-        if(chunkSize != null && chunkSize>0){
-            this.indexingChunkSize = chunkSize;
-        } //else use default value of 1000
-
-        this.modelLocation = new Location(modelDir.getAbsolutePath());
-        this.indexingDataset =  TDBFactory.createDatasetGraph(modelLocation) ;
-        //this.provider = new IndexingModelProvider(this.indexingDir);
-
-        //init entity Ranking
-        try{
-            this.entityRankings = (Map<String,Float>)config.get(KEY_ENTITY_RANKINGS);
-        }catch (RuntimeException e) {
-            log.error("Parsed Entity Rankings MUST use the form Map<String,Float>");
-            System.exit(0);
-        }
-        Object ignore = config.get(KEY_IGNORE_ENTITIES_WITHOUT_ENTITY_RANKING);
-        if(ignore != null){
-            if(ignore instanceof Boolean){
-                this.ignoreEntitiesWithoutRank = (Boolean)ignore;
-            } else {
-                this.ignoreEntitiesWithoutRank = Boolean.parseBoolean(ignore.toString());
-            }
-        }
-        Object defaultRankingObject = config.get(KEY_DEFAULT_ENTITY_RANKING);
-        if(defaultRankingObject != null){
-            float defaultranking = -1;
-            if(defaultRankingObject instanceof Float){
-                defaultranking = (Float)defaultRankingObject;
-            } else {
-                try {
-                    defaultranking = Float.parseFloat(defaultRankingObject.toString());
-                } catch (Exception e) {
-                    log.error("Unable to parse Float value for the Default Entity Ranking from the value parsed for the KEY_DEFAULT_ENTITY_RANKING key (value: "+defaultRankingObject+")");
-                    System.exit(0);
-                }
-            }
-            this.defaultEntityRanking = defaultranking;
-        }
-        Object minimumRequiredRankingObject = config.get(KEY_REQUIRED_ENTITY_RANKING);
-        if(minimumRequiredRankingObject != null){
-            float minRanking = -1;
-            if(minimumRequiredRankingObject instanceof Float){
-                minRanking = (Float)minimumRequiredRankingObject;
-            } else {
-                try {
-                    minRanking = Float.parseFloat(minimumRequiredRankingObject.toString());
-                } catch (Exception e) {
-                    log.error("Unable to parse Float value for the Minimum Required Entity Ranking from the value parsed for the KEY_DEFAULT_ENTITY_RANKING key (value: "+minimumRequiredRankingObject+")");
-                    System.exit(0);
-                }
-            }
-            if(minRanking>=0){ //setting a valid required ranking automatically
-                //means that entities without a rank should be ignored!
-                this.ignoreEntitiesWithoutRank = true;
-            }
-            this.minimumRequiredEntityRanking = minRanking;
-        }
-        Object rankingMode = config.get(KEY_ENTITY_RANKING_BASED_INDEXING_MODE);
-        if(rankingMode != null){
-            if(rankingMode instanceof Boolean){
-                this.rankingMode = (Boolean)rankingMode;
-            } else {
-                this.rankingMode = Boolean.parseBoolean(rankingMode.toString());
-            }
-        }
-        if(this.rankingMode && this.entityRankings == null){
-            log.warn("The Entity Ranking based Indexing Mode can not be activated if no EntityRankings are parsed! -> deactivate Ranking Mode (intertes over all Resources in the RDF Data)");
-            this.rankingMode = false;
-        }
-        Object resumeMode = config.get(KEY_RESUME_MODE);
-        if(resumeMode != null) {
-            if(resumeMode instanceof Boolean){
-                this.resumeMode = (Boolean)resumeMode;
-            } else {
-                this.resumeMode = Boolean.parseBoolean(resumeMode.toString());
-            }
-        } else {
-            this.resumeMode = false;
-        }
-    }
-    public void index() throws YardException{
-        log.info("initialize ...");
-        if(!skipRead){
-            loadRdfFiles();
-        } else {
-            log.info(" ... skiping loading of RDF data");
-        }
-        if(rankingMode){
-            indexRanked();
-        } else {
-            indexResources();
-        }
-        writeCacheBaseConfiguration();
-    }
-    /**
-     * This Method is used to process the RDF Data if all Resource can be indexed,
-     * because it provides the best performance. Mainly because it reads everything
-     * from a single stream and therefore gives the OS the best opportunities to
-     * optimise file access.
-     * @throws YardException
-     */
-    private void indexResources() throws YardException{
+	/**
+	 * Expert only: This allows to set the indexing based on the keys in the map parsed with the
+	 * entity rankings. This will only index entities that are keys in that map.
+	 * If no Map is parsed by {@link #KEY_ENTITY_RANKINGS}, than activating this mode
+	 * will not be successful and a warning will be written.<p>
+	 * This mode is about 50% slower than the usual indexing mode. Therefore this
+	 * mode makes only sense id less than 50% of the entities are indexed.
+	 */
+	public static final String KEY_INDEXING_MODE = "eu.iksproject.rick.indexing.rdf.indexingMode";
+	/**
+	 * If <code>true</code> than no RDF data are loaded. Instead it is assumed, that
+	 * the Graph of the parsed {@link #KEY_MODEL_NAME} already contains all the needed
+	 * data!<p>
+	 * This can be useful if one first wants to index rdf:type A and than rdf:type B
+	 * based on the same set of data
+	 */
+	public static final String KEY_SKIP_READ = "eu.iksproject.rick.indexing.rdf.skipRead";
+	/**
+	 * The number of {@link Representation}s stored at once in the SolrYard!
+	 */
+	public static final String KEY_CHUNK_SIZE = "eu.iksproject.rick.indexing.rdf.chunkSize";
+	/**
+	 * Can be used to parse a map with {@link String} entity id, {@link Float} rank
+	 * for entities.<p>
+	 * Such values are added to Representations for the {@link RdfResourceEnum#signRank}
+	 * field.
+	 */
+	public static final String KEY_ENTITY_RANKINGS = "eu.iksproject.rick.indexing.rdf.entityRankings";
+	/**
+	 * Can be used to activate ignoring of Entities without a page rank
+	 */
+	public static final String KEY_IGNORE_ENTITIES_WITHOUT_ENTITY_RANKING = "eu.iksproject.rick.indexing.rdf.ignoreEntitiesWithoutRankings";
+	/**
+	 * If set to a value >= 0 this is used to exclude Entities with a lower or 
+	 * missing entity rank
+	 */
+	public static final String KEY_REQUIRED_ENTITY_RANKING = "eu.iksproject.rick.indexing.rdf.requiredRanking";
+	/**
+	 * The rank for entities with a missing rank. This takes only effect if
+	 * {@link #KEY_IGNORE_ENTITIES_WITHOUT_ENTITY_RANKING} is set to <code>false</code>
+	 * (the default)
+	 */
+	public static final String KEY_DEFAULT_ENTITY_RANKING = "eu.iksproject.rick.indexing.rdf.defaultRanking";
+	/**
+	 * The resume Mode first checks if a Resource is already present in the parsed
+	 * Yard. If this is the case, than the representation is not indexes again.<p>
+	 * This mode is intended to resume indexing after stopping a previous call before
+	 * finished. The default value = false.
+	 */
+	public static final String KEY_RESUME_MODE = "eu.iksproject.rick.indexing.rdf.resumeMode";
+	
+	private final IndexingMode indexingMode;
+	private final Yard yard;
+	private final ValueFactory vf;
+	private final List<File> rdfFiles;
+	private final File indexingDir;
+	private final String modelName;
+//	private final ParsingProvider parser = new JenaParserProvider();
+	//private final WeightedTcProvider provider;
+	private final FieldMapper mapper;
+	private final Set<String> types;
+	//private MGraph indexingGraph;
+	private final DatasetGraphTDB indexingDataset;
+	private final boolean skipRead;
+	private Location modelLocation;
+	private int indexingChunkSize = 1000;
+	
+	//vars for entity rankings
+	private Map<String,Float> entityRankings = null;
+	private boolean ignoreEntitiesWithoutRank = false;
+	private float defaultEntityRanking = -1;
+	private String entityRankingField = RdfResourceEnum.signRank.getUri();
+	private float minimumRequiredEntityRanking = -1;
+	private boolean resumeMode;
+	
+	
+	public RdfIndexer(Dictionary<String, Object> config){
+		this.yard = (Yard)config.get(KEY_YARD);
+		if(yard == null){
+			throw new IllegalArgumentException("Parsed config MUST CONTAIN a Yard. Use the key "+KEY_YARD+" to parse the YardInstance used to store the geonames.org index!");
+		} else {
+			log.info(String.format("Using Yard %s (id=%s) to index parsed RDF data",
+					yard.getName(),yard.getId()));
+		}
+		this.vf = yard.getValueFactory();
+		Object rdfFiles = config.get(KEY_RDF_FILES);
+		if(rdfFiles instanceof Iterable<?>){
+			this.rdfFiles = new ArrayList<File>();
+			for(Object value : (Iterable<?>)rdfFiles){
+				this.rdfFiles.add(checkFile(value.toString()));
+			}
+		} else {
+			this.rdfFiles = Collections.singletonList(checkFile(rdfFiles.toString()));
+		}
+		Object indexingDir = config.get(KEY_RDF_STORE_DIR);
+		if(indexingDir == null){
+			indexingDir = "indexingData";
+			config.put(KEY_RDF_STORE_DIR, indexingDir);
+		}
+		this.indexingDir = checkFile(indexingDir.toString(), false, true);
+		Object modelName = config.get(KEY_MODEL_NAME);
+		if(modelName == null){
+			modelName = "indexingModel-"+ModelUtils.randomUUID().toString();
+			config.put(KEY_MODEL_NAME, modelName);
+		}
+		this.modelName = modelName.toString();
+		//init the types!
+		Iterable<?> types = (Iterable<?>)config.get(KEY_RDF_TYPES);
+		if(types != null){
+			Set<String> typeSet = new HashSet<String>();
+			for(Object type : types){
+				if(type != null){
+					typeSet.add(type.toString());
+					log.info("  - adding Resoures with rdf:type "+type);
+				}
+			}
+			if(typeSet.isEmpty()){
+				log.info("  - adding all Types (no rdf:type based restriction for RDF Reseource present)");
+				this.types = null;
+			} else {
+				this.types = typeSet;
+			}
+		} else{
+			log.info("  - adding all Types (no rdf:type based restriction for RDF Reseource present)");
+			this.types = null; //null or an iterable with one or more elements!
+		}
+		//init the indexing mode
+		Object indexingMode = config.get(KEY_INDEXING_MODE);
+		if(indexingMode == null){
+			this.indexingMode = IndexingMode.NORMAL; //default to replace
+		} else if(indexingMode instanceof IndexingMode){
+			this.indexingMode = (IndexingMode)indexingMode;
+		} else {
+			try {
+				this.indexingMode = IndexingMode.valueOf(indexingMode.toString());
+			}catch (IllegalArgumentException e) {
+				//catch and re-throw with a better message!
+				throw new IllegalArgumentException(
+						String.format("Values of KEY \"%s\" MUST BE of Type %s or the toString() value MUST BE a member of this Enumeration. If the Key is missing %s is used!",
+								KEY_INDEXING_MODE,IndexingMode.class,IndexingMode.NORMAL),e);
+			}
+		}
+		//init the fieldMapper
+		Iterable<?> mappings = (Iterable<?>)config.get(KEY_FIELD_MAPPINGS);
+		List<FieldMapping> fieldMappings;
+		if(mappings != null){
+			fieldMappings = new ArrayList<FieldMapping>();
+			for(Object mappingString : mappings){
+				if(mappingString != null){
+					FieldMapping fieldMapping = FieldMappingUtils.parseFieldMapping(mappingString.toString());
+					if(fieldMapping != null){
+						fieldMappings.add(fieldMapping);
+					}
+				}
+			}
+			if(!fieldMappings.isEmpty()){
+				this.mapper = new DefaultFieldMapperImpl(ValueConverterFactory.getInstance(vf));
+				for(FieldMapping mapping : fieldMappings){
+					mapper.addMapping(mapping);
+				}
+				//we need to add a mapping for the field rankings (if a mapper is present)
+				mapper.addMapping(new FieldMapping(this.entityRankingField));
+			} else {
+				this.mapper = null;
+			}
+		} else {
+			this.mapper = null;
+		}
+		File modelDir = new File(this.indexingDir,this.modelName);
+		if(!modelDir.exists()){
+			modelDir.mkdir();
+		} else if(!modelDir.isDirectory()){
+			throw new IllegalStateException(String.format("A directory for %s already exists but is not a directory!",modelDir.getAbsoluteFile()));
+		} //else exists and is a dir -> nothing to do
+		Object skipRead = config.get(KEY_SKIP_READ);
+		if(skipRead != null){
+			if(skipRead instanceof Boolean){
+				this.skipRead = ((Boolean)skipRead).booleanValue();
+			} else {
+				this.skipRead = Boolean.parseBoolean(skipRead.toString());
+			}
+		} else {
+			this.skipRead = false;
+		}
+		Integer chunkSize = (Integer)config.get(KEY_CHUNK_SIZE);
+		if(chunkSize != null && chunkSize>0){
+			this.indexingChunkSize = chunkSize;
+		} //else use default value of 1000
+
+		this.modelLocation = new Location(modelDir.getAbsolutePath());
+		this.indexingDataset =  TDBFactory.createDatasetGraph(modelLocation) ;
+		//this.provider = new IndexingModelProvider(this.indexingDir);
+		
+		//init entity Ranking
+		try{
+			this.entityRankings = (Map<String,Float>)config.get(KEY_ENTITY_RANKINGS);
+		}catch (RuntimeException e) {
+			log.error("Parsed Entity Rankings MUST use the form Map<String,Float>");
+			System.exit(0);
+		}
+		Object ignore = config.get(KEY_IGNORE_ENTITIES_WITHOUT_ENTITY_RANKING);
+		if(ignore != null){
+			if(ignore instanceof Boolean){
+				this.ignoreEntitiesWithoutRank = (Boolean)ignore;
+			} else {
+				this.ignoreEntitiesWithoutRank = Boolean.parseBoolean(ignore.toString());
+			}
+		}
+		Object defaultRankingObject = config.get(KEY_DEFAULT_ENTITY_RANKING);
+		if(defaultRankingObject != null){
+			float defaultranking = -1;
+			if(defaultRankingObject instanceof Float){
+				defaultranking = (Float)defaultRankingObject;
+			} else {
+				try {
+					defaultranking = Float.parseFloat(defaultRankingObject.toString());
+				} catch (Exception e) {
+					log.error("Unable to parse Float value for the Default Entity Ranking from the value parsed for the KEY_DEFAULT_ENTITY_RANKING key (value: "+defaultRankingObject+")");
+					System.exit(0);
+				}
+			}
+			this.defaultEntityRanking = defaultranking;
+		}
+		Object minimumRequiredRankingObject = config.get(KEY_REQUIRED_ENTITY_RANKING);
+		if(minimumRequiredRankingObject != null){
+			float minRanking = -1;
+			if(minimumRequiredRankingObject instanceof Float){
+				minRanking = (Float)minimumRequiredRankingObject;
+			} else {
+				try {
+					minRanking = Float.parseFloat(minimumRequiredRankingObject.toString());
+				} catch (Exception e) {
+					log.error("Unable to parse Float value for the Minimum Required Entity Ranking from the value parsed for the KEY_DEFAULT_ENTITY_RANKING key (value: "+minimumRequiredRankingObject+")");
+					System.exit(0);
+				}
+			}
+			if(minRanking>=0){ //setting a valid required ranking automatically
+				//means that entities without a rank should be ignored!
+				this.ignoreEntitiesWithoutRank = true;
+			}
+			this.minimumRequiredEntityRanking = minRanking;
+		}
+
+		Object resumeMode = config.get(KEY_RESUME_MODE);
+		if(resumeMode != null) {
+			if(resumeMode instanceof Boolean){
+				this.resumeMode = (Boolean)resumeMode;
+			} else {
+				this.resumeMode = Boolean.parseBoolean(resumeMode.toString());
+			}
+		} else {
+			this.resumeMode = false;
+		}
+	}
+	public void index() throws YardException{
+		log.info("initialize ...");
+		if(!skipRead){
+			loadRdfFiles();
+		} else {
+			log.info(" ... skiping loading of RDF data");
+		}
+		if(indexingMode == IndexingMode.RANKING_MAP_BASED){
+			indexRanked();
+		} else {
+			indexResources();
+		}
+		writeCacheBaseConfiguration();
+	}
+	/**
+	 * This Method is used to process the RDF Data if all Resource can be indexed,
+	 * because it provides the best performance. Mainly because it reads everything
+	 * from a single stream and therefore gives the OS the best opportunities to
+	 * optimise file access.
+	 * @throws YardException
+	 */
+	private void indexResources() throws YardException{
         StringBuilder qb = new StringBuilder();
         /*
          * NOTES:

Added: incubator/stanbol/trunk/rick/indexing/genericRdf/src/main/java/eu/iksproject/rick/indexing/rdf/RdfIndexerConfig.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/rick/indexing/genericRdf/src/main/java/eu/iksproject/rick/indexing/rdf/RdfIndexerConfig.java?rev=1058959&view=auto
==============================================================================
--- incubator/stanbol/trunk/rick/indexing/genericRdf/src/main/java/eu/iksproject/rick/indexing/rdf/RdfIndexerConfig.java (added)
+++ incubator/stanbol/trunk/rick/indexing/genericRdf/src/main/java/eu/iksproject/rick/indexing/rdf/RdfIndexerConfig.java Fri Jan 14 11:39:26 2011
@@ -0,0 +1,408 @@
+package eu.iksproject.rick.indexing.rdf;
+
+import static eu.iksproject.rick.indexing.rdf.RdfIndexer.*;
+
+import java.io.File;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Dictionary;
+import java.util.HashSet;
+import java.util.Hashtable;
+import java.util.Map;
+import java.util.Set;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import eu.iksproject.rick.core.mapping.FieldMappingUtils;
+import eu.iksproject.rick.servicesapi.mapping.FieldMapper;
+import eu.iksproject.rick.servicesapi.mapping.FieldMapping;
+import eu.iksproject.rick.servicesapi.model.Representation;
+import eu.iksproject.rick.servicesapi.model.rdf.RdfResourceEnum;
+import eu.iksproject.rick.servicesapi.yard.Yard;
+
+/**
+ * API based Configuration for the {@link Dictionary} based configuration of the 
+ * {@link RdfIndexer} class.
+ * 
+ * @author Rupert Westenthaler
+ * 
+ */
+public class RdfIndexerConfig {
+    
+    Logger log = LoggerFactory.getLogger(RdfIndexerConfig.class);
+    Dictionary<String,Object> config = new Hashtable<String,Object>();
+    
+/**
+     * Constructs a minimal configuration for a Yard and a list of RDF Files
+     * to be indexed. Parsed files are checked for existences and read access.<p>
+     * Note that:<ul>
+     * <li><code>{@link Yard#getId()}+"_indexingData"</code> is used as the
+     * directory for indexing (use {@link #setIndexingDir(File)} to change this
+     * default).
+     * <li><code>{@link Yard#getId()}+"_model"</code> is used as modelName for
+     * the name of the Model (use {@link #setModelName(String)} to change this
+     * default).
+     * <li> if the list of the parsed files is <code>null</code> or empty, than
+     * the {@link #setSkipRead(Boolean) is set to <code>true</code>. This means
+     * that it is assumed that the RDF Model (name: #getModelName() and part of
+     * the RDF triple store located at #getIndexingDir()) already contains all
+     * the RDF data needed for the indexing. Otherwise the all parsed files are
+     * checked for existence and read access and #setSkipRead(Boolean) is set to
+     * <code>false</code>. This will trigger to read the RDF data of that files
+     * to be stored in the RDF model with the configured name and the Triple
+     * Store with the configured location.
+     * </ul>
+     * @param yard The {@link Yard} used to store the RDF data
+     * @param rdfFiles the RDF files to index.
+     */
+    public RdfIndexerConfig(Yard yard, File... rdfFiles) {
+        if (yard == null) {
+            throw new IllegalArgumentException("The parsed Yard MUST NOT be NULL");
+        }
+        config.put(KEY_YARD, yard);
+        setIndexingDir(new File(yard.getId() + "_indexingData"));
+        setModelName(yard.getId() + "_model");
+        if (rdfFiles == null || rdfFiles.length < 1) {
+            log.info("no RDF Files parsed -> set skipRead to TRUE");
+            setSkipRead(Boolean.TRUE);
+        } else {
+            addSourceFile(rdfFiles);
+        }
+    }
+    
+    /**
+     * Adds the parsed source files. Checks for {@link File#exists()}, {@link File#isFile()} and
+     * {@link File#canRead()}. Files that do not pase this test are ignored.
+     * 
+     * @param sourceFiles
+     *            the source files to add
+     */
+    public void addSourceFile(File... sourceFiles) {
+        if (sourceFiles != null) {
+            for (File sourceFile : sourceFiles) {
+                checkAndAddSrouceFile(sourceFile);
+            }
+        }
+    }
+    
+    /**
+     * Remove the parsed source files
+     * 
+     * @param sourceFile
+     *            the source files to remove
+     */
+    public void removeSourceFile(File... sourceFile) {
+        if (sourceFile == null) {
+            return;
+        }
+        Set<File> files = (Set<File>) config.get(KEY_RDF_FILES);
+        if (files != null) {
+            files.removeAll(Arrays.asList(sourceFile));
+        }
+    }
+    
+    /**
+     * Getter for the list of RDF files used as source for indexing.
+     * 
+     * @return the unmodifiable list of files or <code>null</code>if no source files are present.
+     */
+    public Collection<File> getSourceFiles() {
+        Collection<File> sourceFiles = (Collection<File>) config.get(KEY_RDF_FILES);
+        return sourceFiles == null ? null : Collections.unmodifiableCollection((Collection<File>) config
+                .get(KEY_RDF_FILES));
+    }
+    
+    /**
+     * Setter for the directory used to store the data of the RDF triple store used for indexing.
+     * 
+     * @param file
+     *            the directory used to store the data (created if not exist)
+     * @return <code>true</code> if the parsed file can be used as indexing
+     *     directory (exists and is a directory or !exists) 
+     */
+    public boolean setIndexingDir(File file) throws IllegalArgumentException {
+        if (checkFile(file, false, null)) { // isDirectory or !exists
+            config.put(KEY_RDF_STORE_DIR, file);
+            return true;
+        } else {
+            return false;
+        }
+    }
+    /**
+     * Getter for the indexing directory
+     * @return the directory used for indexing
+     */
+    public File getIndexingDir() {
+        return (File) config.get(KEY_RDF_STORE_DIR);
+    }
+    /**
+     * Setter for the RDF model name used to store/access the RDF data used
+     * for indexing
+     * @param modelName the RDF model name
+     */
+    public void setModelName(String modelName) {
+        if (modelName != null && !modelName.isEmpty()) {
+            config.put(KEY_MODEL_NAME, modelName);
+        } else {
+            log.warn("Unable to set modelName to NULL or an empty String");
+        }
+    }
+    /**
+     * Getter for the RDF model name used to store/access the RDF data used
+     * for indexing
+     * @return the RDF model name
+     */
+    public String getModelName() {
+        return (String) config.get(KEY_MODEL_NAME);
+    }
+    /**
+     * Setter for the (optional) map that uses entity ids as key and there 
+     * ranking as value. see {@link RdfResourceEnum#signRank} for more information
+     * about ranking of entities)
+     * @param entityRankings the entity ranking map
+     */
+    public void setEntityRankings(Map<String,Float> entityRankings) {
+        if (entityRankings == null) {
+            config.remove(KEY_ENTITY_RANKINGS);
+        } else {
+            config.put(KEY_ENTITY_RANKINGS, entityRankings);
+        }
+    }
+    /**
+     * Getter for the (optional) map that uses entity ids as key and there 
+     * ranking as value. see {@link RdfResourceEnum#signRank} for more information
+     * about ranking of entities)
+     * @return the entity rankings or <code>null</code> if no entity rankings
+     * are present
+     */
+    public Map<String,Float> getNetityRankings() {
+        return (Map<String,Float>) config.get(KEY_ENTITY_RANKINGS);
+    }
+    /**
+     * Setter for the indexing mode (expert use only). Please carefully read
+     * {@link RdfIndexer#KEY_INDEXING_MODE} before setting this property.
+     * @param mode the indexing mode
+     */
+    public void setIndexingMode(IndexingMode mode) {
+        if (mode != null) {
+            config.put(KEY_INDEXING_MODE, mode);
+        } else {
+            config.remove(KEY_INDEXING_MODE);
+        }
+    }
+    /**
+     * Getter for the Indexing Mode
+     * @return the indexing mode or <code>null</code> if not set by this
+     * configuration.
+     */
+    public IndexingMode getIndexingMode() {
+        return (IndexingMode) config.get(KEY_INDEXING_MODE);
+    }
+    /**
+     * Setter for the skip reading mode. If set to <code>true</code> no RDF
+     * data are read. This can be useful if the RDF data are
+     * already available as an Jena TDB store (e.g. when interrupting an
+     * indexing session that has already completed with reading the RDF data.
+     * @param state the state or <code>null</code> to remove any present config
+     */
+    public void setSkipRead(Boolean state) {
+        if (state == null) {
+            config.remove(KEY_SKIP_READ);
+        } else {
+            config.put(KEY_SKIP_READ, state);
+        }
+    }
+    /**
+     * Getter for the skip reading state.
+     * @return the state or <code>null</code> if not set
+     */
+    public Boolean getSkipRead() {
+        return (Boolean) config.get(KEY_SKIP_READ);
+    }
+    /**
+     * This is the number of documents stored in the {@link Yard} at once. During
+     * indexing {@link Representation} are created based on the RDF data of the
+     * configured RDF source files. As soon as chink size Representations are
+     * created they are stored by a single call to {@link Yard#store(Iterable)}.
+     * @param size the number of {@link Representation} stored at in the {@link Yard}
+     * at once. Parse <code>null</code> or a value smaller equals zero to remove
+     * this optional configuration.
+     */
+    public void setChunkSize(Integer size) {
+        if (size == null || size < 1) {
+            config.remove(KEY_CHUNK_SIZE);
+        } else {
+            config.put(KEY_CHUNK_SIZE, size);
+        }
+    }
+    /**
+     * Getter for the chunk size (number of {@link Representation} sotred at once
+     * in the {@link Yard}.
+     * @return the chunk size or <code>null</code> if not present
+     */
+    public Integer getChunkSize() {
+        return (Integer) config.get(KEY_CHUNK_SIZE);
+    }
+    /**
+     * Allows to set the state if Entities without ranking information should be
+     * ignored by the indexer.
+     * @param state the state or <code>null</code> to remove the configuration
+     * and go with the default.
+     */
+    public void setIgnoreEntitiesWithoutRanking(Boolean state) {
+        if (state == null) {
+            config.remove(KEY_IGNORE_ENTITIES_WITHOUT_ENTITY_RANKING);
+        } else {
+            config.put(KEY_IGNORE_ENTITIES_WITHOUT_ENTITY_RANKING, state);
+        }
+    }
+    /**
+     * Getter for the state if entities without available ranking should be
+     * ignored.
+     * @return the state or <code>null</code> if not present
+     */
+    public Boolean getIgnoreEntitiesWithoutRanking() {
+        return (Boolean) config.get(KEY_IGNORE_ENTITIES_WITHOUT_ENTITY_RANKING);
+    }
+    /**
+     * Setter for the minimal ranking required by an entity to be processed
+     * by the indexer.
+     * @param minRanking the minimum ranking. Parsed <code>null</code> or a
+     * value smaller equals 0 to remove this configuration and go with the
+     * default.
+     */
+    public void setMinEntityRanking(Float minRanking) {
+        if (minRanking == null || minRanking <= 0) {
+            config.remove(KEY_REQUIRED_ENTITY_RANKING);
+        } else {
+            config.put(KEY_REQUIRED_ENTITY_RANKING, minRanking);
+        }
+    }
+    /**
+     * The minimum required ranking required by an entity to be indexed.
+     * @return the minimum required ranking or <code>null</code> if not defined
+     * by this configuration
+     */
+    public Float getMinEntityRanking() {
+        return (Float) config.get(KEY_REQUIRED_ENTITY_RANKING);
+    }
+    /**
+     * Setter for the ranking used for entities for them no ranking is
+     * available. The value need to be greater than zero to be accepted.
+     * @param defaultRanking the ranking used for entities without ranking
+     * information. Parse <code>null</code> or a value smaller equals zero to
+     * remove this configuration.
+     */
+    public void setDefaultEntityRanking(Float defaultRanking) {
+        if (defaultRanking == null || defaultRanking <= 0) {
+            config.remove(defaultRanking);
+        } else {
+            config.put(KEY_DEFAULT_ENTITY_RANKING, defaultRanking);
+        }
+    }
+    /**
+     * Getter for the default ranking value that is used for entities no ranking
+     * information are available.
+     * @return the default ranking or <code>null</code> if not present within
+     * this configuration.
+     */
+    public Float getDefaultEntityRanking() {
+        return (Float) config.get(KEY_DEFAULT_ENTITY_RANKING);
+    }
+    
+    /**
+     * Tests if a RDF source file is valid (exists, isFile and canRead) and
+     * if OK add them to the configuration.
+     * @param sourceFile the file to add
+     */
+    private void checkAndAddSrouceFile(File sourceFile) {
+        if (checkFile(sourceFile, true, true)) {
+            Set<File> files = (Set<File>) config.get(KEY_RDF_FILES);
+            if (files == null) {
+                files = new HashSet<File>();
+                config.put(KEY_RDF_FILES, files);
+            }
+            log.info("  > add source file " + sourceFile);
+            files.add(sourceFile);
+        }
+    }
+    /**
+     * Setter for the field mappings used by the indexer to create the
+     * {@link Representation}s based on the RDF input.<br>
+     * Parsd strings must represent valid field mappings.
+     * @param mappings A collection field mappings in the string representation.
+     * If <code>null</code> or an empty collection is parsed the configuration
+     * is removed.
+     */
+    public void setMappings(Collection<String> mappings){
+        if(mappings == null || mappings.isEmpty()){
+            config.remove(KEY_FIELD_MAPPINGS);
+        } else {
+            config.put(KEY_FIELD_MAPPINGS, mappings);
+        }
+    }
+    /**
+     * Setter for the field mappings that allows to parse an existing
+     * {@link FieldMapper} instance. Note that the string representation of all
+     * the {@link FieldMapping}s part of the FieldMapper will be stored within
+     * the configuration
+     * @param mapper the FieldMapper instance with the FieldMappings to be used
+     * for the configuration of the indexer.
+     */
+    public void setMappings(FieldMapper mapper){
+        if(mapper != null){
+            String[] mappingStrings = FieldMappingUtils.serialiseFieldMapper(mapper);
+            setMappings(mappingStrings != null ? Arrays.asList(mappingStrings):null);
+        } else {
+            setMappings((Collection<String>)null);
+        }
+    }
+    /**
+     * Getter for the field mappings
+     * @return the field mappings or <code>null</code> if no are defined for
+     * this configuration.
+     */
+    public Collection<String> getMappings(){
+        Collection<String> mappings = (Collection<String>)config.get(KEY_FIELD_MAPPINGS);
+        return mappings == null ? null: Collections.unmodifiableCollection(mappings);
+    }
+    /**
+     * checks a files against the parsed parameter
+     * @param file the file to check
+     * @param isFile if <code>true</code> than the parsed {@link File} is tested
+     * to be a file, otherwise it is test to be a directory
+     * @param exists if <code>null</code> it is indicated that the file/directory
+     * can bee created if necessary. <code>true</code> indicated that the parsed
+     * file must exist where <code>false</code> indicate that the file MUST NOT
+     * exists.
+     * @return <code>true</code> if the parsed {@link File} fulfils the stated
+     * requirements.
+     */
+    private boolean checkFile(File file, boolean isFile, Boolean exists) {
+        //exists null means that it will be created if not existence
+        //therefore we need only to check the state if not null.
+        if (exists != null) {
+            if (file.exists() != exists) {
+                log.warn(String.format("parsed File %s does %s exist, but the other state was requested", file, file.exists() ? "" : "not"));
+                return false;
+            }
+        } else if (!file.exists()) {
+            //in case of exists == null && file does not exist we assume that
+            //the File (or Directory) will be created. Therefore no further
+            //checks are required
+            return true;
+        } //else the parsed file exists -> perform the other checks
+        if (file.isFile() != isFile) {
+            log.warn(String.format("parsed File %s is a %s but %s was requested!", 
+                file, file.isFile() ? "File" : "Directory",isFile ? "File" : "Directory"));
+            return false;
+        }
+        if (!file.canRead()) {
+            log.warn(String.format("Unable to read parsed File %s", file));
+            return false;
+        }
+        return true;
+    }
+}

Propchange: incubator/stanbol/trunk/rick/indexing/genericRdf/src/main/java/eu/iksproject/rick/indexing/rdf/RdfIndexerConfig.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: incubator/stanbol/trunk/rick/model/clerezza/pom.xml
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/rick/model/clerezza/pom.xml?rev=1058959&r1=1058958&r2=1058959&view=diff
==============================================================================
--- incubator/stanbol/trunk/rick/model/clerezza/pom.xml (original)
+++ incubator/stanbol/trunk/rick/model/clerezza/pom.xml Fri Jan 14 11:39:26 2011
@@ -123,6 +123,12 @@
     </dependency> -->
     <!-- for tests -->
     <dependency>
+      <groupId>eu.iksproject</groupId>
+      <artifactId>eu.iksproject.rick.test</artifactId>
+      <version>0.1-SNAPSHOT</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
       <groupId>junit</groupId>
       <artifactId>junit</artifactId>
       <version>4.7</version>

Modified: incubator/stanbol/trunk/rick/model/clerezza/src/main/java/eu/iksproject/rick/model/clerezza/RdfReference.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/rick/model/clerezza/src/main/java/eu/iksproject/rick/model/clerezza/RdfReference.java?rev=1058959&r1=1058958&r2=1058959&view=diff
==============================================================================
--- incubator/stanbol/trunk/rick/model/clerezza/src/main/java/eu/iksproject/rick/model/clerezza/RdfReference.java (original)
+++ incubator/stanbol/trunk/rick/model/clerezza/src/main/java/eu/iksproject/rick/model/clerezza/RdfReference.java Fri Jan 14 11:39:26 2011
@@ -10,10 +10,22 @@ import eu.iksproject.rick.servicesapi.mo
 public class RdfReference implements Reference,Cloneable {
     private final UriRef uri;
     protected RdfReference(String reference){
-        this.uri = new UriRef(reference);
+        if(reference == null){
+            throw new NullPointerException("The parsed Reference MUST NOT be NULL!");
+        } else if(reference.isEmpty()){
+            throw new IllegalArgumentException("The parsed Reference MUST NOT be Empty!");
+        } else {
+            this.uri = new UriRef(reference);
+        }
     }
     protected RdfReference(UriRef uri){
-        this.uri = uri;
+        if(uri == null){
+            throw new NullPointerException("The parsed Reference MUST NOT be NULL!");
+        } else if(uri.getUnicodeString().isEmpty()){
+            throw new IllegalArgumentException("The parsed Reference MUST NOT be represent an empty string!");
+        } else {
+            this.uri = uri;
+        }
     }
     @Override
     public String getReference() {

Modified: incubator/stanbol/trunk/rick/model/clerezza/src/main/java/eu/iksproject/rick/model/clerezza/RdfRepresentation.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/rick/model/clerezza/src/main/java/eu/iksproject/rick/model/clerezza/RdfRepresentation.java?rev=1058959&r1=1058958&r2=1058959&view=diff
==============================================================================
--- incubator/stanbol/trunk/rick/model/clerezza/src/main/java/eu/iksproject/rick/model/clerezza/RdfRepresentation.java (original)
+++ incubator/stanbol/trunk/rick/model/clerezza/src/main/java/eu/iksproject/rick/model/clerezza/RdfRepresentation.java Fri Jan 14 11:39:26 2011
@@ -16,13 +16,14 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import eu.iksproject.rick.core.utils.AdaptingIterator;
+import eu.iksproject.rick.core.utils.FilteringIterator;
 import eu.iksproject.rick.core.utils.ModelUtils;
 import eu.iksproject.rick.core.utils.TypeSaveIterator;
 import eu.iksproject.rick.model.clerezza.impl.Literal2TextAdapter;
 import eu.iksproject.rick.model.clerezza.impl.LiteralAdapter;
-import eu.iksproject.rick.model.clerezza.impl.NaturalLanguageLiteralIterator;
-import eu.iksproject.rick.model.clerezza.impl.ReferenceIterator;
+import eu.iksproject.rick.model.clerezza.impl.NaturalTextFilter;
 import eu.iksproject.rick.model.clerezza.impl.Resource2ValueAdapter;
+import eu.iksproject.rick.model.clerezza.impl.UriRef2ReferenceAdapter;
 import eu.iksproject.rick.model.clerezza.impl.UriRefAdapter;
 import eu.iksproject.rick.model.clerezza.utils.Resource2StringAdapter;
 import eu.iksproject.rick.servicesapi.model.Reference;
@@ -64,13 +65,13 @@ public class RdfRepresentation implement
     }
     @Override
     public void add(String field, Object value) {
-        if(field == null) {
-            throw new IllegalArgumentException("Parameter \"String field\" MUST NOT be NULL!");
+        if(field == null){
+            throw new NullPointerException("The parsed field MUST NOT be NULL");
+        } else if(field.isEmpty()){
+            throw new IllegalArgumentException("The parsed field MUST NOT be Empty");
         }
         if(value == null){
-            log.warn("NULL parsed as value in add method for symbol "+getId()
-                    +" and field "+field+" -> call ignored");
-            return;
+            throw new IllegalArgumentException("NULL values are not supported by Representations");
         }
         UriRef fieldUriRef = new UriRef(field);
         Collection<Object> values = new ArrayList<Object>();
@@ -86,7 +87,6 @@ public class RdfRepresentation implement
                 graphNode.addProperty(fieldUriRef, ((RdfReference) current).getUriRef());
             } else if (current instanceof Reference){
                 graphNode.addProperty(fieldUriRef, new UriRef(((Reference) current).getReference()));
-                addReference(field,((Reference)current).getReference());
             } else if (current instanceof RdfText){
                 //treat RDF Implementations special to avoid creating new instances
                 graphNode.addProperty(fieldUriRef,((RdfText) current).getLiteral());
@@ -111,30 +111,32 @@ public class RdfRepresentation implement
     }
     @Override
     public void addReference(String field, String reference) {
-        if(field == null) {
-            throw new IllegalArgumentException("Parameter \"String field\" MUST NOT be NULL!");
+        if(field == null){
+            throw new NullPointerException("The parsed field MUST NOT be NULL");
+        } else if(field.isEmpty()){
+            throw new IllegalArgumentException("The parsed field MUST NOT be Empty");
         }
         if(reference == null){
-            log.warn("NULL parsed as value in add method for symbol "+getId()
-                    +" and field "+field+" -> call ignored");
+            throw new IllegalArgumentException("NULL values are not supported by Representations");
+        } else if (reference.isEmpty()) {
+            throw new IllegalArgumentException("References MUST NOT be empty!");
         }
         graphNode.addProperty(new UriRef(field), new UriRef(reference));
     }
     @Override
     public void addNaturalText(String field, String text, String...languages) {
-        if(field == null) {
-            throw new IllegalArgumentException("Parameter \"String field\" MUST NOT be NULL!");
+        if(field == null){
+            throw new NullPointerException("The parsed field MUST NOT be NULL");
+        } else if(field.isEmpty()){
+            throw new IllegalArgumentException("The parsed field MUST NOT be Empty");
         }
         if(text == null){
-            log.warn("NULL parsed as value in add method for symbol "+getId()
-                    +" and field "+field+" -> call ignored");
+            throw new IllegalArgumentException("NULL values are not supported by Representations");
         }
         this.addNaturalText(new UriRef(field), text, languages);
     }
     private void addNaturalText(UriRef field, String text, String...languages) {
-        if(languages == null){
-            log.debug("NULL parsed as languages -> replacing with \"new String []{null}\"" +
-                    " -> assuming a missing explicit cast to (Stirng) in the var arg");
+        if(languages == null || languages.length == 0){
             languages = new String []{null};
         }
         for(String language : languages){
@@ -145,22 +147,33 @@ public class RdfRepresentation implement
     @SuppressWarnings("unchecked")
     @Override
     public <T> Iterator<T> get(String field, final Class<T> type) throws UnsupportedTypeException {
+        if(field == null){
+            throw new NullPointerException("The parsed field MUST NOT be NULL");
+        } else if(field.isEmpty()){
+            throw new IllegalArgumentException("The parsed field MUST NOT be Empty");
+        }
         UriRef fieldUriRef = new UriRef(field);
         if(Resource.class.isAssignableFrom(type)){ //native support for Clerezza types
             return new TypeSaveIterator<T>(graphNode.getObjects(fieldUriRef), type);
-        } else if(type.equals(String.class)){ //support to convert anything to String
-            return (Iterator<T>) new AdaptingIterator<Resource,String>(
-                    graphNode.getObjects(fieldUriRef),
-                    new Resource2StringAdapter<Resource>(),
-                    String.class);
+// NOTE: (Rupert Westenthaler 12.01.2011)
+//     Converting everything to String is not an intended functionality. When
+//     someone parsed String.class he rather assumes that he gets only string
+//     values and not also string representations for Dates, Integer ...
+//       
+//        } else if(type.equals(String.class)){ //support to convert anything to String
+//            return (Iterator<T>) new AdaptingIterator<Resource,String>(
+//                    graphNode.getObjects(fieldUriRef),
+//                    new Resource2StringAdapter<Resource>(),
+//                    String.class);
         } else if(type.equals(URI.class) || type.equals(URL.class)){ //support for References
             return new AdaptingIterator<UriRef, T>(
                     graphNode.getUriRefObjects(fieldUriRef),
                     new UriRefAdapter<T>(),
                     type);
         } else if(Reference.class.isAssignableFrom(type)){
-            return (Iterator<T>) new ReferenceIterator(
-                    graphNode.getUriRefObjects(fieldUriRef));
+            return (Iterator<T>) new AdaptingIterator<UriRef,Reference>(
+                    graphNode.getUriRefObjects(fieldUriRef),
+                    new UriRef2ReferenceAdapter(),Reference.class);
         } else if(Text.class.isAssignableFrom(type)){
             return (Iterator<T>)new AdaptingIterator<Literal, Text>(
                     graphNode.getLiterals(fieldUriRef),
@@ -176,12 +189,23 @@ public class RdfRepresentation implement
 
     @Override
     public Iterator<Reference> getReferences(String field) {
-        Iterator<UriRef> it = graphNode.getUriRefObjects(new UriRef(field));
-        return new ReferenceIterator(it);
+        if(field == null){
+            throw new NullPointerException("The parsed field MUST NOT be NULL");
+        } else if(field.isEmpty()){
+            throw new IllegalArgumentException("The parsed field MUST NOT be Empty");
+        }
+        return new AdaptingIterator<UriRef,Reference>(
+                graphNode.getUriRefObjects(new UriRef(field)),
+                new UriRef2ReferenceAdapter(),Reference.class);
     }
 
     @Override
     public Iterator<Text> getText(String field) {
+        if(field == null){
+            throw new NullPointerException("The parsed field MUST NOT be NULL");
+        } else if(field.isEmpty()){
+            throw new IllegalArgumentException("The parsed field MUST NOT be Empty");
+        }
         return new AdaptingIterator<Literal, Text>(
                 graphNode.getLiterals(new UriRef(field)),
                 new Literal2TextAdapter<Literal>(),
@@ -190,16 +214,21 @@ public class RdfRepresentation implement
 
     @Override
     public Iterator<Object> get(String field) {
+        if(field == null){
+            throw new NullPointerException("The parsed field MUST NOT be NULL");
+        } else if(field.isEmpty()){
+            throw new IllegalArgumentException("The parsed field MUST NOT be Empty");
+        }
         return new AdaptingIterator<Resource, Object>(graphNode.getObjects(new UriRef(field)),
                 new Resource2ValueAdapter<Resource>(),Object.class);
     }
 
     @Override
     public Iterator<Text> get(String field, String...languages) {
-        if(languages == null){
-            log.debug("NULL parsed as languages -> replacing with \"new String []{null}\"" +
-                    " -> assuming a missing explicit cast to (String) in the var arg");
-            languages = new String []{null};
+        if(field == null){
+            throw new NullPointerException("The parsed field MUST NOT be NULL");
+        } else if(field.isEmpty()){
+            throw new IllegalArgumentException("The parsed field MUST NOT be Empty");
         }
         return new AdaptingIterator<Literal, Text>(
                 graphNode.getLiterals(new UriRef(field)),
@@ -215,6 +244,11 @@ public class RdfRepresentation implement
 
     @Override
     public <T> T getFirst(String field, Class<T> type) throws UnsupportedTypeException {
+        if(field == null){
+            throw new NullPointerException("The parsed field MUST NOT be NULL");
+        } else if(field.isEmpty()){
+            throw new IllegalArgumentException("The parsed field MUST NOT be Empty");
+        }
         Iterator<T> it = get(field,type);
         if(it.hasNext()){
             return it.next();
@@ -225,6 +259,11 @@ public class RdfRepresentation implement
 
     @Override
     public Object getFirst(String field) {
+        if(field == null){
+            throw new NullPointerException("The parsed field MUST NOT be NULL");
+        } else if(field.isEmpty()){
+            throw new IllegalArgumentException("The parsed field MUST NOT be Empty");
+        }
         Iterator<Object> it = get(field);
         if(it.hasNext()){
             return it.next();
@@ -234,11 +273,21 @@ public class RdfRepresentation implement
     }
     @Override
     public Reference getFirstReference(String field) {
+        if(field == null){
+            throw new NullPointerException("The parsed field MUST NOT be NULL");
+        } else if(field.isEmpty()){
+            throw new IllegalArgumentException("The parsed field MUST NOT be Empty");
+        }
         Iterator<Reference> it = getReferences(field);
         return it.hasNext()?it.next():null;
     }
     @Override
     public Text getFirst(String field, String...languages) {
+        if(field == null){
+            throw new NullPointerException("The parsed field MUST NOT be NULL");
+        } else if(field.isEmpty()){
+            throw new IllegalArgumentException("The parsed field MUST NOT be Empty");
+        }
         if(languages == null){
             log.debug("NULL parsed as languages -> replacing with \"new String []{null}\"" +
                     " -> assuming a missing explicit cast to (String) in the var arg");
@@ -257,37 +306,47 @@ public class RdfRepresentation implement
     }
 
     @Override
-    public void remove(String field, Object value) {
-        if(field == null) {
-            throw new IllegalArgumentException("Parameter \"String field\" MUST NOT be NULL!");
+    public void remove(String field, Object parsedValue) {
+        if(field == null){
+            throw new NullPointerException("The parsed field MUST NOT be NULL");
+        } else if(field.isEmpty()){
+            throw new IllegalArgumentException("The parsed field MUST NOT be Empty");
         }
-        if(value == null){
+        if(parsedValue == null){
             log.warn("NULL parsed as value in remove method for symbol "+getId()
                     +" and field "+field+" -> call ignored");
+            return;
         }
         UriRef fieldUriRef = new UriRef(field);
-        if(value instanceof Resource){ //native support for Clerezza types!
-            graphNode.deleteProperty(fieldUriRef, (Resource)value);
-        } else if(value instanceof URI || value instanceof URL){
-            removeReference(field, value.toString());
-        } else if (value instanceof String[]){
-            if(((String[])value).length>0){
-                if(((String[])value).length>1){
-                    removeNaturalText(field, ((String[])value)[0],((String[])value)[1]);
-                } else {
-                    removeNaturalText(field, ((String[])value)[0],(String)null);
-                }
+        Collection<Object> removeValues = new ArrayList<Object>();
+        
+        ModelUtils.checkValues(valueFactory, parsedValue, removeValues);
+        //We still need to implement support for specific types supported by this implementation
+        for (Object current : removeValues){
+            if (current instanceof Resource){ //native support for Clerezza types!
+                graphNode.deleteProperty(fieldUriRef, (Resource)current);
+            } else if (current instanceof RdfReference){
+                //treat RDF Implementations special to avoid creating new instances
+                graphNode.deleteProperty(fieldUriRef, ((RdfReference) current).getUriRef());
+            } else if (current instanceof Reference){
+                graphNode.deleteProperty(fieldUriRef, new UriRef(((Reference) current).getReference()));
+            } else if (current instanceof RdfText){
+                //treat RDF Implementations special to avoid creating new instances
+                graphNode.deleteProperty(fieldUriRef,((RdfText) current).getLiteral());
+            } else if (current instanceof Text){
+                removeNaturalText(field,((Text)current).getText(),((Text)current).getLanguage());
+            } else { //else add an typed Literal!
+                removeTypedLiteral(fieldUriRef, current);
             }
-        } else {
-            removeTypedLiteral(fieldUriRef, value);
         }
-
     }
 
     @Override
     public void removeReference(String field, String reference) {
-        if(field == null) {
-            throw new IllegalArgumentException("Parameter \"String field\" MUST NOT be NULL!");
+        if(field == null){
+            throw new NullPointerException("The parsed field MUST NOT be NULL");
+        } else if(field.isEmpty()){
+            throw new IllegalArgumentException("The parsed field MUST NOT be Empty");
         }
         if(reference == null){
             log.warn("NULL parsed as value in remove method for symbol "+getId()+" and field "+field+" -> call ignored");
@@ -307,48 +366,59 @@ public class RdfRepresentation implement
     }
     @Override
     public void removeNaturalText(String field, String value, String... languages) {
-        if(field == null) {
-            throw new IllegalArgumentException("Parameter \"String field\" MUST NOT be NULL!");
+        if(field == null){
+            throw new NullPointerException("The parsed field MUST NOT be NULL");
+        } else if(field.isEmpty()){
+            throw new IllegalArgumentException("The parsed field MUST NOT be Empty");
         }
         if(value == null){
             log.warn("NULL parsed as value in remove method for symbol "+getId()+" and field "+field+" -> call ignored");
         }
-        if(languages == null){
-            log.debug("NULL parsed as languages -> replacing with \"new String []{null}\"" +
-                    " -> assuming a missing explicit cast to (Stirng) in the var arg");
+        if(languages == null || languages.length == 0){ //null or no language
+            //need to be interpreted as default language
             languages = new String []{null};
         }
         UriRef fieldUriRef = new UriRef(field);
         for(String language : languages){
             graphNode.deleteProperty(fieldUriRef,RdfResourceUtils.createLiteral(value, language));
+            if(language == null){ //if the language is null
+                //we need also try to remove a typed Literal with the data type
+                //xsd:string and the parsed value!
+                graphNode.deleteProperty(fieldUriRef,RdfResourceUtils.createLiteral(value));
+            }
         }
     }
     @Override
     public void removeAll(String field) {
+        if(field == null){
+            throw new NullPointerException("The parsed field MUST NOT be NULL");
+        } else if(field.isEmpty()){
+            throw new IllegalArgumentException("The parsed field MUST NOT be Empty");
+        }
         graphNode.deleteProperties(new UriRef(field));
     }
     @Override
     public void removeAllNaturalText(String field, String... languages) {
-        if(field == null) {
-            throw new IllegalArgumentException("Parameter \"String field\" MUST NOT be NULL!");
-        }
-        if(languages == null){
-            log.debug("NULL parsed as languages -> replacing with \"new String []{null}\"" +
-                    " -> assuming a missing explicit cast to (Stirng) in the var arg");
-            languages = new String []{null};
-        }
+        if(field == null){
+            throw new NullPointerException("The parsed field MUST NOT be NULL");
+        } else if(field.isEmpty()){
+            throw new IllegalArgumentException("The parsed field MUST NOT be Empty");
+        }
+//        if(languages == null || languages.length == 0){
+//            languages = new String []{null};
+//        }
         UriRef fieldUriRef = new UriRef(field);
-        Collection<Literal> literals = new ArrayList<Literal>();
         //get all the affected Literals
-        for (Iterator<Literal> it =  new NaturalLanguageLiteralIterator(graphNode.getLiterals(fieldUriRef), languages);
-            it.hasNext();
-            literals.add(it.next())
-        );
-        //delete the found literals
-        for(Literal literal:literals){
-            graphNode.deleteProperty(fieldUriRef, literal);
+        Collection<Literal> toRemove = new ArrayList<Literal>();
+        Iterator<Literal> it =  new FilteringIterator<Literal>(
+                graphNode.getLiterals(fieldUriRef),
+                new NaturalTextFilter(languages),Literal.class);
+        while(it.hasNext()){
+            toRemove.add(it.next());
+        }
+        for(Literal l : toRemove){
+            graphNode.deleteProperty(fieldUriRef, l);
         }
-
     }
 
     @Override
@@ -361,7 +431,7 @@ public class RdfRepresentation implement
 
     @Override
     public void setReference(String field, String reference) {
-        removeAll(reference);
+        removeAll(field);
         if(reference != null){
             addReference(field, reference);
         }
@@ -374,5 +444,18 @@ public class RdfRepresentation implement
             addNaturalText(field, text, languages);
         }
     }
+    
+    @Override
+    public String toString() {
+        return RdfRepresentation.class.getSimpleName()+getId();
+    }
+    @Override
+    public int hashCode() {
+        return getId().hashCode();
+    }
+    @Override
+    public boolean equals(Object obj) {
+        return obj != null && obj instanceof Representation && ((Representation)obj).getId().equals(getId());
+    }
 
 }

Modified: incubator/stanbol/trunk/rick/model/clerezza/src/main/java/eu/iksproject/rick/model/clerezza/RdfText.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/rick/model/clerezza/src/main/java/eu/iksproject/rick/model/clerezza/RdfText.java?rev=1058959&r1=1058958&r2=1058959&view=diff
==============================================================================
--- incubator/stanbol/trunk/rick/model/clerezza/src/main/java/eu/iksproject/rick/model/clerezza/RdfText.java (original)
+++ incubator/stanbol/trunk/rick/model/clerezza/src/main/java/eu/iksproject/rick/model/clerezza/RdfText.java Fri Jan 14 11:39:26 2011
@@ -15,6 +15,14 @@ public class RdfText implements Text, Cl
     private final boolean isPlain;
 
     protected RdfText(String text, String lang) {
+        if(text == null){
+            throw new NullPointerException("The parsed text MUST NOT be NULL");
+        } else if(text.isEmpty()){
+            throw new IllegalArgumentException("Tha parsed Text MUST NOT be empty!");
+        }
+        if(lang != null && lang.isEmpty()){ //we need to avoid empty languages, because Clerezza don't like them!
+            lang = null;
+        }
         this.literal = new PlainLiteralImpl(text, lang != null ? new Language(lang) : null);
         this.isPlain = true;
     }
@@ -26,7 +34,9 @@ public class RdfText implements Text, Cl
 
     @Override
     public String getLanguage() {
-        return isPlain && ((PlainLiteral) literal).getLanguage() != null ? ((PlainLiteral) literal).getLanguage().toString() : null;
+        return isPlain && 
+            ((PlainLiteral) literal).getLanguage() != null ? 
+                ((PlainLiteral) literal).getLanguage().toString() : null;
     }
 
     @Override

Modified: incubator/stanbol/trunk/rick/model/clerezza/src/main/java/eu/iksproject/rick/model/clerezza/RdfValueFactory.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/rick/model/clerezza/src/main/java/eu/iksproject/rick/model/clerezza/RdfValueFactory.java?rev=1058959&r1=1058958&r2=1058959&view=diff
==============================================================================
--- incubator/stanbol/trunk/rick/model/clerezza/src/main/java/eu/iksproject/rick/model/clerezza/RdfValueFactory.java (original)
+++ incubator/stanbol/trunk/rick/model/clerezza/src/main/java/eu/iksproject/rick/model/clerezza/RdfValueFactory.java Fri Jan 14 11:39:26 2011
@@ -40,7 +40,7 @@ public class RdfValueFactory implements 
     @Override
     public RdfReference createReference(Object value) {
         if (value == null) {
-            throw new IllegalArgumentException("The parsed value MUST NOT be NULL");
+            throw new NullPointerException("The parsed value MUST NOT be NULL");
         } else if (value instanceof UriRef) {
             return new RdfReference((UriRef) value);
         } else {
@@ -51,7 +51,7 @@ public class RdfValueFactory implements 
     @Override
     public RdfText createText(Object value) {
         if (value == null) {
-            throw new IllegalArgumentException("The parsed value MUST NOT be NULL");
+            throw new NullPointerException("The parsed value MUST NOT be NULL");
         } else if (value instanceof Literal) {
             return new RdfText((Literal) value);
         } else {
@@ -66,10 +66,13 @@ public class RdfValueFactory implements 
 
     @Override
     public RdfRepresentation createRepresentation(String id) {
-        if (id == null || id.isEmpty()) {
-            throw new IllegalArgumentException("The parsed id MUST NOT be NULL nor empty!");
+        if (id == null){
+           throw new NullPointerException("The parsed id MUST NOT be NULL!");
+        } else if(id.isEmpty()){
+            throw new IllegalArgumentException("The parsed id MUST NOT be empty!");
+        } else {
+            return createRdfRepresentation(new UriRef(id), new SimpleMGraph());
         }
-        return createRdfRepresentation(new UriRef(id), new SimpleMGraph());
     }
 
     /**
@@ -84,7 +87,10 @@ public class RdfValueFactory implements 
      */
     public RdfRepresentation createRdfRepresentation(UriRef node, TripleCollection graph) {
         if (node == null) {
-            throw new IllegalArgumentException("The parsed id MUST NOT be NULL!");
+            throw new NullPointerException("The parsed id MUST NOT be NULL!");
+        }
+        if(graph == null){
+            throw new NullPointerException("The parsed graph MUST NOT be NULL!");
         }
         return new RdfRepresentation(node, graph);
     }

Modified: incubator/stanbol/trunk/rick/model/clerezza/src/main/java/eu/iksproject/rick/model/clerezza/impl/Literal2TextAdapter.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/rick/model/clerezza/src/main/java/eu/iksproject/rick/model/clerezza/impl/Literal2TextAdapter.java?rev=1058959&r1=1058958&r2=1058959&view=diff
==============================================================================
--- incubator/stanbol/trunk/rick/model/clerezza/src/main/java/eu/iksproject/rick/model/clerezza/impl/Literal2TextAdapter.java (original)
+++ incubator/stanbol/trunk/rick/model/clerezza/src/main/java/eu/iksproject/rick/model/clerezza/impl/Literal2TextAdapter.java Fri Jan 14 11:39:26 2011
@@ -6,12 +6,17 @@ import java.util.HashSet;
 import java.util.Set;
 
 import org.apache.clerezza.rdf.core.Literal;
+import org.apache.clerezza.rdf.core.LiteralFactory;
 import org.apache.clerezza.rdf.core.PlainLiteral;
 import org.apache.clerezza.rdf.core.TypedLiteral;
+import org.apache.clerezza.rdf.core.UriRef;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import eu.iksproject.rick.core.utils.AdaptingIterator.Adapter;
 import eu.iksproject.rick.model.clerezza.RdfResourceUtils;
 import eu.iksproject.rick.model.clerezza.RdfValueFactory;
+import eu.iksproject.rick.servicesapi.defaults.DataTypeEnum;
 import eu.iksproject.rick.servicesapi.model.Text;
 /**
  * This Adapter does two things:
@@ -30,7 +35,13 @@ import eu.iksproject.rick.servicesapi.mo
  * @author Rupert Westenthaler
  */
 public class Literal2TextAdapter<T extends Literal> implements Adapter<T,Text> {
-
+    
+    private Logger log = LoggerFactory.getLogger(Literal2TextAdapter.class);
+    /**
+     * The xsd:string data type constant used for TypedLiterals to check if the
+     * represent an string value!
+     */
+    private static UriRef xsdString = new UriRef(DataTypeEnum.String.getUri());
     /**
      * Unmodifiable set of the active languages
      */
@@ -60,17 +71,24 @@ public class Literal2TextAdapter<T exten
     @Override
     public Text adapt(T value, Class<Text> type) {
         if(value instanceof PlainLiteral){
-            if(languages == null || languages.contains(((PlainLiteral) value).getLanguage())){
+            String literalLang = ((PlainLiteral) value).getLanguage() == null ? 
+                    null : ((PlainLiteral) value).getLanguage().toString();
+            if(languages == null || languages.contains(literalLang)){
                 return valueFactory.createText(value);
             } //else wrong language -> filter
-        } else if(containsNull){
-            /*
-             * if the null language is active, than we can also return
-             * "normal" literals (with no known language).
-             * But first we need to check the Datatype!
-             */
-            return valueFactory.createText(value);
-        } // else no language defined -> filter
+        } else if(value instanceof TypedLiteral) {
+            if(containsNull && ((TypedLiteral)value).getDataType().equals(xsdString)){
+                /*
+                 * if the null language is active, than we can also return
+                 * "normal" literals (with no known language).
+                 * But first we need to check the Datatype!
+                 */
+                return valueFactory.createText(value);
+            } // else no xsd:string dataType and therefore not a text with default lang!
+        } else {// unknown Literal type -> filter + warning
+            log.warn(String.format("Unknown LiteralType %s (lexicalForm=\"%s\") -> ignored! Pleas adapt this implementation to support this type!",
+                value.getClass(),value.getLexicalForm()));
+        }
         return null;
     }
 

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=1058959&r1=1058958&r2=1058959&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 Fri Jan 14 11:39:26 2011
@@ -40,9 +40,16 @@ public class LiteralAdapter<T extends Li
     @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)){
+// NOTE: (Rupert Westenthaler 12.01.2011)
+//      Converting everything to String is not an intended functionality. When
+//      someone parsed String.class he rather assumes that he gets only string
+//      values and not also string representations for Dates, Integer ...
+//      If someone needs this kind of functionality he can anyway use the 
+//      the Resource2StringAdapter.
+//        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()))){

Added: incubator/stanbol/trunk/rick/model/clerezza/src/main/java/eu/iksproject/rick/model/clerezza/impl/NaturalTextFilter.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/rick/model/clerezza/src/main/java/eu/iksproject/rick/model/clerezza/impl/NaturalTextFilter.java?rev=1058959&view=auto
==============================================================================
--- incubator/stanbol/trunk/rick/model/clerezza/src/main/java/eu/iksproject/rick/model/clerezza/impl/NaturalTextFilter.java (added)
+++ incubator/stanbol/trunk/rick/model/clerezza/src/main/java/eu/iksproject/rick/model/clerezza/impl/NaturalTextFilter.java Fri Jan 14 11:39:26 2011
@@ -0,0 +1,86 @@
+package eu.iksproject.rick.model.clerezza.impl;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.clerezza.rdf.core.Literal;
+import org.apache.clerezza.rdf.core.PlainLiteral;
+import org.apache.clerezza.rdf.core.TypedLiteral;
+import org.apache.clerezza.rdf.core.UriRef;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import eu.iksproject.rick.core.utils.FilteringIterator;
+import eu.iksproject.rick.core.utils.FilteringIterator.Filter;
+import eu.iksproject.rick.servicesapi.defaults.DataTypeEnum;
+/**
+ * Filter implementation to be used in combination with {@link FilteringIterator}
+ * to return only {@link Literal} values (may be {@link PlainLiteral}s and/or
+ * {@link TypedLiteral}s) that confirm to the parsed set of languages.<p>
+ * Parsing <code>null</code>, an empty array is interpreted such that any
+ * language is accepted. Parsing "" or <code>null</code> as one element of the
+ * array indicated that Literals without any language tag are included. This also
+ * includes {@link TypedLiteral}s with the data type <code>xsd:string</code>.<p>
+ * Note that parsing:<ul>
+ * <li> an empty array will result in all Literals (regardless of the language)
+ *      are returned
+ * <li> an array that contains only the <code>null</code> element will result in
+ *      only Literals without any language tag are returned.
+ * </ul>
+ * 
+ * @author Rupert Westenthaler
+ *
+ */
+public class NaturalTextFilter implements Filter<Literal> {
+    Logger log = LoggerFactory.getLogger(NaturalTextFilter.class);
+    /**
+     * The xsd:string data type constant used for TypedLiterals to check if the
+     * represent an string value!
+     */
+    private static UriRef xsdString = new UriRef(DataTypeEnum.String.getUri());
+    protected final Set<String> languages;
+    private final boolean containsNull;
+
+    public NaturalTextFilter(String...languages){
+        if(languages == null || languages.length == 0){
+            this.languages = null;
+            this.containsNull = true; // if no language is parse accept any (also the default)
+        } else {
+            Set<String> languageSet = new HashSet<String>(Arrays.asList(languages));
+            if(languageSet.remove("")){
+                /*
+                 * Parsing "" as language needs to be interpreted as parsing
+                 * null
+                 */
+                languageSet.add(null);
+            }
+            this.languages = Collections.unmodifiableSet(languageSet);
+            this.containsNull = this.languages.contains(null);
+        }
+    }
+    @Override
+    public boolean isValid(Literal value) {
+        if (value instanceof PlainLiteral){
+           if(languages == null) { //no language restrictions
+                return true; //return any Plain Literal
+            } else {
+                String literalLang = ((PlainLiteral) value).getLanguage() == null ?
+                    null : ((PlainLiteral) value).getLanguage().toString();
+                return languages.contains(literalLang);
+            }
+        } else if(value instanceof TypedLiteral){
+            /*
+             * if the null language is active, than we can also return
+             * "normal" literals (with no known language). This includes
+             * Types literals with the data type xsd:string
+             */
+            return containsNull && ((TypedLiteral)value).getDataType().equals(xsdString);
+        } else {// unknown Literal type -> filter + warning
+            log.warn(String.format("Unknown LiteralType %s (lexicalForm=\"%s\") -> ignored! Pleas adapt this implementation to support this type!",
+                value.getClass(),value.getLexicalForm()));
+            return false;
+        }
+    }
+}

Propchange: incubator/stanbol/trunk/rick/model/clerezza/src/main/java/eu/iksproject/rick/model/clerezza/impl/NaturalTextFilter.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/stanbol/trunk/rick/model/clerezza/src/main/java/eu/iksproject/rick/model/clerezza/impl/UriRef2ReferenceAdapter.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/rick/model/clerezza/src/main/java/eu/iksproject/rick/model/clerezza/impl/UriRef2ReferenceAdapter.java?rev=1058959&view=auto
==============================================================================
--- incubator/stanbol/trunk/rick/model/clerezza/src/main/java/eu/iksproject/rick/model/clerezza/impl/UriRef2ReferenceAdapter.java (added)
+++ incubator/stanbol/trunk/rick/model/clerezza/src/main/java/eu/iksproject/rick/model/clerezza/impl/UriRef2ReferenceAdapter.java Fri Jan 14 11:39:26 2011
@@ -0,0 +1,24 @@
+package eu.iksproject.rick.model.clerezza.impl;
+
+import org.apache.clerezza.rdf.core.UriRef;
+
+import eu.iksproject.rick.core.utils.AdaptingIterator.Adapter;
+import eu.iksproject.rick.model.clerezza.RdfValueFactory;
+import eu.iksproject.rick.servicesapi.model.Reference;
+
+/**
+ * Adapter that converts Clerezza {@link UriRef} instances to {@link Reference}s.
+ * The {@link RdfValueFactory} is used to create {@link Reference} instances.
+ * @author Rupert Westenthaler
+ *
+ */
+public class UriRef2ReferenceAdapter implements Adapter<UriRef,Reference> {
+
+    private final RdfValueFactory valueFactory = RdfValueFactory.getInstance();
+
+    @Override
+    public Reference adapt(UriRef value, Class<Reference> type) {
+        return valueFactory.createReference(value);
+    }
+
+}

Propchange: incubator/stanbol/trunk/rick/model/clerezza/src/main/java/eu/iksproject/rick/model/clerezza/impl/UriRef2ReferenceAdapter.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain