Free cookie consent management tool by TermsFeed Policy Generator

Changeset 1116 for branches


Ignore:
Timestamp:
01/13/09 15:07:31 (16 years ago)
Author:
gkronber
Message:

worked on CEDMA DB-backend. Select() interface to RDF_Store is not powerful enough => need Query() interface. #419
(work in progress - doesn't build!)

Location:
branches/CEDMA-Refactoring-Ticket419
Files:
2 added
10 edited

Legend:

Unmodified
Added
Removed
  • branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.Core/DataSet.cs

    r1106 r1116  
    4848        // lazy loading of problem from DB
    4949        if (problem == null) {
    50           IList<Statement> persistedData = Store.Select(new Statement(new Entity(Ontology.CedmaNameSpace + Guid), Ontology.PredicateSerializedData, Ontology.AnyEntity));
    51           if (persistedData.Count == 1) {
    52             Literal persistedLiteral = (Literal)persistedData[0].Property;
     50          var persistedData = Store.Select(new Statement(new Entity(Ontology.CedmaNameSpace + Guid), Ontology.PredicateSerializedData, Ontology.AnyEntity));
     51          if (persistedData.Count() == 1) {
     52            Literal persistedLiteral = (Literal)persistedData.First().Property;
    5353            this.problem = (Problem)PersistenceManager.RestoreFromGZip(Convert.FromBase64String((string)persistedLiteral.Value));
    5454          } else
    5555            this.problem = new Problem(); // no entry in the DB => create a new problem
    5656        }
    57         return problem; 
     57        return problem;
    5858      }
    5959    }
     
    6969      Store = store;
    7070      guid = new Guid(dataSetEntity.Uri.Remove(0, Ontology.CedmaNameSpace.Length));
    71       IList<Statement> names = store.Select(new Statement(dataSetEntity, Ontology.PredicateName, Ontology.AnyEntity));
    72       if (names.Count > 0) name = (string)((Literal)names[0].Property).Value;
     71      var names = store.Select(new Statement(dataSetEntity, Ontology.PredicateName, Ontology.AnyEntity));
     72      if (names.Count() > 0) name = (string)((Literal)names.First().Property).Value;
    7373      else name = guid.ToString();
    7474    }
  • branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.Core/DataSetList.cs

    r992 r1116  
    4141        store = value;
    4242        Action reload = ReloadList;
    43         lock(dataSetList) {
     43        lock (dataSetList) {
    4444          dataSetList.Clear();
    4545        }
     
    5858
    5959    private void ReloadList() {
    60       IList<Statement> statements = store.Select(new Statement(Ontology.AnyEntity, Ontology.PredicateInstanceOf, Ontology.TypeDataSet));
    61       foreach(Statement s in statements) {
     60      var statements = store.Select(new Statement(Ontology.AnyEntity, Ontology.PredicateInstanceOf, Ontology.TypeDataSet));
     61      foreach (Statement s in statements) {
    6262        DataSet d = new DataSet(store, s.Subject);
    63         lock(dataSetList) {
     63        lock (dataSetList) {
    6464          dataSetList.Add(d);
    6565        }
     
    7070    public IEnumerator<DataSet> GetEnumerator() {
    7171      List<DataSet> dataSets = new List<DataSet>();
    72       lock(dataSets) {
     72      lock (dataSets) {
    7373        dataSets.AddRange(dataSetList);
    7474      }
  • branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.Core/DataSetView.cs

    r1109 r1116  
    8484        };
    8585        worker.DoWork += delegate(object doWorkSender, DoWorkEventArgs doWorkArgs) {
    86           worker.ReportProgress(10);
    87           results.GetEntries().Last(); // preload list by accessing last element
     86          int n = results.GetEntries().Count();
     87          int i = 0;
     88          // preload list
     89          foreach (var entry in results.GetEntries()) {
     90            i++;
     91            if((((i*100) / n) % 10) == 0) worker.ReportProgress((i * 100) / n);
     92          }
    8893          worker.ReportProgress(100);
    8994        };
  • branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.Core/Results.cs

    r1109 r1116  
    6464
    6565    private List<ResultsEntry> entries = null;
     66    private bool cached = false;
    6667    public IEnumerable<ResultsEntry> GetEntries() {
    67       if (entries == null)
    68         Reload();
     68      if (!cached)
     69        return SelectRows();
    6970      return entries.AsEnumerable();
    70     }
    71 
    72     internal void Reload() {
    73       entries = SelectRows().ToList();
    74       FireChanged();
    7571    }
    7672
     
    7874      if (store == null) yield break;
    7975
    80       var results = store.Select(new Statement(dataSetEntity, Ontology.PredicateHasModel, Ontology.AnyEntity))
    81          .SelectMany(x => store.Select(new SelectFilter(
    82            new Entity[] { (Entity)x.Property },
    83            new Entity[] { Ontology.PredicateModelAttribute },
    84            new Resource[] { Ontology.AnyEntity })))
    85          .SelectMany(x =>
    86            store.Select(
    87               new SelectFilter(
    88               new Entity[] { (Entity)x.Property },
    89               new Entity[] { Ontology.PredicateModelAttributeName },
    90               new Entity[] { Ontology.AnyEntity })).Select(y =>
    91                 new {
    92                   Model = x.Subject,
    93                   Attribute = (Entity)x.Property,
    94                   AttributeName = (Literal)y.Property
    95                 }))
    96          .SelectMany(x =>
    97            store.Select(
    98              new Statement(x.Attribute, Ontology.PredicateModelAttributeValue, Ontology.AnyEntity))
    99              .Select(y =>
    100                new {
    101                  Model = x.Model.Uri,
    102                  AttributeName = x.AttributeName.Value,
    103                  AttributeValue = ((Literal)y.Property).Value
    104                })).GroupBy(x => x.Model);
     76      var models = store.Select(new Statement(dataSetEntity, Ontology.PredicateHasModel, Ontology.AnyEntity));
    10577
     78      //var results = store.Select(new Statement(dataSetEntity, Ontology.PredicateHasModel, Ontology.AnyEntity))
     79      //   .SelectMany(x => store.Select(new SelectFilter(
     80      //     new Entity[] { (Entity)x.Property },
     81      //     new Entity[] { Ontology.PredicateModelAttribute },
     82      //     new Resource[] { Ontology.AnyEntity })))
     83      //   .SelectMany(x =>
     84      //     store.Select(
     85      //        new SelectFilter(
     86      //        new Entity[] { (Entity)x.Property },
     87      //        new Entity[] { Ontology.PredicateModelAttributeName },
     88      //        new Entity[] { Ontology.AnyEntity })).Select(y =>
     89      //          new {
     90      //            Model = x.Subject,
     91      //            Attribute = (Entity)x.Property,
     92      //            AttributeName = (Literal)y.Property
     93      //          }))
     94      //   .SelectMany(x =>
     95      //     store.Select(
     96      //       new Statement(x.Attribute, Ontology.PredicateModelAttributeValue, Ontology.AnyEntity))
     97      //       .Select(y =>
     98      //         new {
     99      //           Model = x.Model.Uri,
     100      //           AttributeName = x.AttributeName.Value,
     101      //           AttributeValue = ((Literal)y.Property).Value
     102      //         })).GroupBy(x => x.Model);
    106103
    107       Random random = new Random();
     104      entries = new List<ResultsEntry>();
     105      foreach (var model in models) {
     106        var attributes = store.Select(new Statement((Entity)model.Property, Ontology.PredicateModelAttribute, Ontology.AnyEntity));
     107
     108        foreach (var attr in attributes) {
     109          var namesAndValues = store
     110            .Select(new SelectFilter(new Entity[] { (Entity)attr.Property },
     111              new Entity[] { Ontology.PredicateModelAttributeName, Ontology.PredicateModelAttributeValue },
     112              new Entity[] { Ontology.AnyEntity }));
     113        }
     114      }
     115
    108116      foreach (var row in results) {
    109117        ResultsEntry entry = new ResultsEntry(row.First().Model);
     
    111119          entry.Set((string)attr.AttributeName, attr.AttributeValue);
    112120        }
     121        entries.Add(entry);
    113122        yield return entry;
    114123      }
     124
     125      FireChanged();
     126      cached = true;
    115127    }
    116128
     
    120132      var attributeNames =
    121133        store.Select(new Statement(Ontology.AnyEntity, Ontology.PredicateModelAttributeName, Ontology.AnyEntity))
    122         .Select(s => (string)((Literal)s.Property).Value)
     134        .Select(s => (string)((Literal)s.Property).Value)       
    123135        .Distinct();
    124136      foreach (var name in attributeNames) {
  • branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.DB.Interfaces/HeuristicLab.CEDMA.DB.Interfaces.csproj

    r988 r1116  
    7070  </ItemGroup>
    7171  <ItemGroup>
     72    <Compile Include="IVariableBindings.cs" />
    7273    <Compile Include="Ontology.cs" />
    7374    <Compile Include="SelectFilter.cs" />
  • branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.DB.Interfaces/IStore.cs

    r551 r1116  
    3535
    3636    [OperationContract]
    37     IList<Statement> Select(Statement template);
    38 
    39     [OperationContract(Name = "SelectFiltered")]
    40     IList<Statement> Select(SelectFilter filter);
     37    ICollection<IVariableBindings> Select(ICollection<Statement> query);
    4138  }
    4239}
  • branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.DB/HeuristicLab.CEDMA.DB.csproj

    r1041 r1116  
    7474  </ItemGroup>
    7575  <ItemGroup>
     76    <Compile Include="VariableBindings.cs" />
    7677    <Compile Include="Store.cs" />
    7778    <Compile Include="HeuristicLabCedmaDbPlugin.cs" />
  • branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.DB/Store.cs

    r957 r1116  
    4242    private object bigLock = new object();
    4343    public Store(string connectionString) {
    44       lock(bigLock) {
     44      lock (bigLock) {
    4545        this.connectionString = connectionString;
    4646        store = SemWeb.Store.Create(connectionString);
     
    4949
    5050    public void Add(Statement statement) {
    51       lock(bigLock) {
     51      lock (bigLock) {
    5252        store.Add(Translate(statement));
    5353      }
    5454    }
    5555
    56     public IList<Statement> Select(Statement template) {
    57       SemWeb.SelectResult result;
    58       lock(bigLock) {
    59         result = store.Select(Translate(template));
    60       }
    61       List<Statement> r = new List<Statement>();
    62       foreach(SemWeb.Statement resultStatement in result) {
    63         r.Add(Translate(resultStatement));
    64       }
    65       return r;
     56    public ICollection<IVariableBindings> Select(ICollection<Statement> query) {
     57      SemWeb.Query.QueryResultSink resultSink = new MyQueryResultSink();
     58      Translate(query).Run(store, resultSink);
     59      return resultSink.Bindings;
    6660    }
    6761
    68     public IList<Statement> Select(SelectFilter filter) {
    69       SemWeb.SelectResult result;
    70       lock(bigLock) {
    71         result = store.Select(Translate(filter));
     62    private SemWeb.Query.Query Translate(ICollection<Statement> query) {
     63      SemWeb.Query.GraphMatch graphMatch = new SemWeb.Query.GraphMatch();
     64      foreach(Statement statement in query) {
     65        graphMatch.AddGraphStatement(Translate(statement));
    7266      }
    73       List<Statement> r = new List<Statement>();
    74       foreach(SemWeb.Statement resultStatement in result) {
    75         r.Add(Translate(resultStatement));
    76       }
    77       return r;
     67      return graphMatch;
    7868    }
     69
     70
     71    //public ICollection<Statement> Select(Statement template) {
     72    //  SemWeb.MemoryStore memStore = new SemWeb.MemoryStore();
     73    //  lock (bigLock) {
     74    //    store.Select(Translate(template), memStore);
     75    //  }
     76    //  return memStore.Select(x=>Translate(x)).ToList();
     77    //}
     78
     79    //public ICollection<Statement> Select(SelectFilter filter) {
     80    //  SemWeb.MemoryStore memStore = new SemWeb.MemoryStore();
     81    //  lock (bigLock) {
     82    //    store.Select(Translate(filter), memStore);
     83    //  }
     84    //  return memStore.Select(x => Translate(x)).ToList();
     85    //}
    7986
    8087    private SemWeb.SelectFilter Translate(SelectFilter filter) {
     
    9198
    9299    private SemWeb.Resource Translate(Resource prop) {
    93       if(prop is Literal) {
     100      if (prop is Literal) {
    94101        return TranslateLiteral((Literal)prop);
    95       } else if(prop is SerializedLiteral) {
     102      } else if (prop is SerializedLiteral) {
    96103        return TranslateLiteral((SerializedLiteral)prop);
    97104      } else {
     
    101108
    102109    private Statement Translate(SemWeb.Statement statement) {
    103       if(statement.Object is SemWeb.Literal) {
     110      if (statement.Object is SemWeb.Literal) {
    104111        return new Statement(
    105112          new Entity(statement.Subject.Uri),
     
    122129
    123130    private SemWeb.Literal TranslateLiteral(SerializedLiteral l) {
    124       if(l.RawData == null) return null;
     131      if (l.RawData == null) return null;
    125132      return new SemWeb.Literal(l.RawData, null, "serializedItem");
    126133    }
    127134
    128135    private SemWeb.Literal TranslateLiteral(Literal l) {
    129       if(l.Value == null) return null;
    130       if(l.Value is double) return SemWeb.Literal.FromValue((double)l.Value);
    131       else if(l.Value is bool) return SemWeb.Literal.FromValue((bool)l.Value);
    132       else if(l.Value is int) return SemWeb.Literal.FromValue((int)l.Value);
    133       else if(l.Value is long) return SemWeb.Literal.FromValue((long)l.Value);
    134       else if(l.Value is string) return SemWeb.Literal.FromValue((string)l.Value);
     136      if (l.Value == null) return null;
     137      if (l.Value is double) return SemWeb.Literal.FromValue((double)l.Value);
     138      else if (l.Value is bool) return SemWeb.Literal.FromValue((bool)l.Value);
     139      else if (l.Value is int) return SemWeb.Literal.FromValue((int)l.Value);
     140      else if (l.Value is long) return SemWeb.Literal.FromValue((long)l.Value);
     141      else if (l.Value is string) return SemWeb.Literal.FromValue((string)l.Value);
    135142      else return new SemWeb.Literal(l.Value.ToString());
    136143    }
    137144
    138145    private Resource TranslateLiteral(SemWeb.Literal l) {
    139       if(l.DataType == "serializedItem") {
     146      if (l.DataType == "serializedItem") {
    140147        return new SerializedLiteral(l.Value);
    141       } else if(l.DataType != null) {
     148      } else if (l.DataType != null) {
    142149        return new Literal(l.ParseValue());
    143150      } else {
  • branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.Server/Dispatcher.cs

    r1115 r1116  
    5252    private void FillDispatchQueue() {
    5353      Dictionary<Entity, Dictionary<int, int>> numberOfModelsOfTargetVariableOfDataSet = new Dictionary<Entity, Dictionary<int, int>>();
    54       IList<Statement> datasetStatements = store.Select(new Statement(Ontology.AnyEntity, Ontology.PredicateInstanceOf, Ontology.TypeDataSet));
     54      var datasetStatements = store.Select(new Statement(Ontology.AnyEntity, Ontology.PredicateInstanceOf, Ontology.TypeDataSet));
    5555      foreach (Statement datasetStatement in datasetStatements) {
    5656        numberOfModelsOfTargetVariableOfDataSet.Add(datasetStatement.Subject, new Dictionary<int, int>());
    57         IList<Statement> modelStatements = store.Select(new Statement(datasetStatement.Subject, Ontology.PredicateHasModel, Ontology.AnyEntity));
     57        var modelStatements = store.Select(new Statement(datasetStatement.Subject, Ontology.PredicateHasModel, Ontology.AnyEntity));
    5858        foreach (Statement modelStatement in modelStatements) {
    59           IList<Statement> modelAttributeStatements = store.Select(new Statement((Entity)modelStatement.Property, Ontology.PredicateModelAttribute, Ontology.AnyEntity));
     59          var modelAttributeStatements = store.Select(new Statement((Entity)modelStatement.Property, Ontology.PredicateModelAttribute, Ontology.AnyEntity));
    6060          foreach (Statement modelAttrStatement in modelAttributeStatements) {
    6161            var targetVariableStatements = store.Select(new Statement((Entity)modelAttrStatement.Property, Ontology.PredicateModelAttributeName, Ontology.AnyEntity))
  • branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.Server/Executer.cs

    r1115 r1116  
    117117       
    118118      byte[] serializedModel = PersistenceManager.SaveToGZip(bestModelScope.GetVariableValue("FunctionTree", false));
    119       store.Add(new Statement(modelEntity, Ontology.PredicateSerializedData, new Literal(serializedModel)));
     119      store.Add(new Statement(modelEntity, Ontology.PredicateSerializedData, new Literal(Convert.ToBase64String(serializedModel))));
    120120
    121121    }
Note: See TracChangeset for help on using the changeset viewer.