Class SchemaMapperImpl

java.lang.Object
org.aksw.jenax.arq.schema_mapping.SchemaMapperImpl

public class SchemaMapperImpl extends Object
SchemaMapper for mapping RDF tables ("result sets") to SQL tables. The schema mapper is independent of any instance data an operates only based on a given set of source variables (column names) together with statistic providers. As a consequence it is possible to create schema mappings for concrete SPARQL result sets as well as from schemas of virtual result sets such as obtained by rewriting a SPARQL query w.r.t. a set of R2RML mappings. Example for using this class in conjunction with BindingAnalytics on a concrete SPARQL result set:
 
 List<Binding> bindings = rs...;
 Set<Var> resultVars = rs...;

 Map<Var, Entry<Multiset<String>, Long>> usedDatatypesAndNulls = bindings.stream()
    .collect(ResultSetAnalytics.usedDatatypesAndNullCounts(resultVars).asCollector());

 SchemaMapperImpl.newInstance()
     .setSourceVars(resultVars)
     .setSourceVarToDatatypes(v -> usedDatatypesAndNulls.get(v).getKey().elementSet())
     .setSourceVarToNulls(v -> usedDatatypesAndNulls.get(v).getValue())
     .setTypePromotionStrategy(TypePromoterImpl.create())
     .createSchemaMapping();
 
 
Author:
Claus Stadler
  • Field Details

    • sourceVars

      protected Set<org.apache.jena.sparql.core.Var> sourceVars
    • sourceVarToDatatypes

      protected Function<? super org.apache.jena.sparql.core.Var,? extends Set<String>> sourceVarToDatatypes
    • sourceVarToNulls

      protected Function<? super org.apache.jena.sparql.core.Var,? extends Number> sourceVarToNulls
    • typeRemap

      protected Function<String,String> typeRemap
    • typeConversionSupplier

      protected BiFunction<String,String,? extends ExprRewrite> typeConversionSupplier
    • varToFallbackDatatype

      protected Function<? super org.apache.jena.sparql.core.Var,String> varToFallbackDatatype
    • typePromotionStrategy

      protected org.aksw.jenax.arq.schema_mapping.TypePromoter typePromotionStrategy
  • Constructor Details

    • SchemaMapperImpl

      public SchemaMapperImpl()
  • Method Details

    • setSourceVars

      public SchemaMapperImpl setSourceVars(Set<org.apache.jena.sparql.core.Var> sourceVars)
      Set the set of columns of the source schema (represented as variables) which participate in the schema mapping.
    • getSourceVars

      public Set<org.apache.jena.sparql.core.Var> getSourceVars()
    • setSourceVarToDatatypes

      public SchemaMapperImpl setSourceVarToDatatypes(Function<? super org.apache.jena.sparql.core.Var,? extends Set<String>> sourceVarToDatatypes)
    • setSourceVarToNulls

      public SchemaMapperImpl setSourceVarToNulls(Function<? super org.apache.jena.sparql.core.Var,? extends Number> sourceVarToNulls)
    • setVarToFallbackDatatype

      public SchemaMapperImpl setVarToFallbackDatatype(Function<? super org.apache.jena.sparql.core.Var,String> varToFallbackDatatype)
    • setVarToFallbackDatatype

      public SchemaMapperImpl setVarToFallbackDatatype(String datatype)
      Sets (and overrides) the fallback for any variable to the given argument. Calls setVarToFallbackDatatype(Function).
    • setVarToFallbackDatatypeToString

      public SchemaMapperImpl setVarToFallbackDatatypeToString()
      Convenience method to set (and override) the fallback datatype to xsd:string. Calls setVarToFallbackDatatype(Function).
    • getTypeRemap

      public Function<String,String> getTypeRemap()
    • setTypeRemap

      public SchemaMapperImpl setTypeRemap(Function<String,String> typeRemap)
    • getTypeConversionSupplier

      public BiFunction<String,String,? extends ExprRewrite> getTypeConversionSupplier()
    • setTypeConversionSupplier

      public SchemaMapperImpl setTypeConversionSupplier(BiFunction<String,String,? extends ExprRewrite> typeConversionSupplier)
    • setTypePromotionStrategy

      public SchemaMapperImpl setTypePromotionStrategy(org.aksw.jenax.arq.schema_mapping.TypePromoter typePromotionStrategy)
      The type promotion strategy. This can be used to reduce the number of columns in the target schema by combining weaker types with mightier ones, such as by promoting short to int. The strategy may even promote integer types to floating point ones.
      Parameters:
      typePromotionStrategy -
      Returns:
    • deriveSuffix

      public static String deriveSuffix(String datatype)
    • createSchemaMapping

      public SchemaMapping createSchemaMapping()
    • defaultTypeConversionSupplier

      public static ExprRewrite defaultTypeConversionSupplier(String srcDatatypeIri, String tgtDatatypeIri)
    • createDatatypeCheck

      public static org.apache.jena.sparql.expr.Expr createDatatypeCheck(org.apache.jena.sparql.expr.Expr expr, String datatypeIri)
    • createColumnName

      public static String createColumnName(String varName, String datatypeIri)
    • newInstance

      public static SchemaMapperImpl newInstance()