Changeset 1116 for branches/CEDMA-Refactoring-Ticket419
- Timestamp:
- 01/13/09 15:07:31 (16 years ago)
- 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 48 48 // lazy loading of problem from DB 49 49 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; 53 53 this.problem = (Problem)PersistenceManager.RestoreFromGZip(Convert.FromBase64String((string)persistedLiteral.Value)); 54 54 } else 55 55 this.problem = new Problem(); // no entry in the DB => create a new problem 56 56 } 57 return problem; 57 return problem; 58 58 } 59 59 } … … 69 69 Store = store; 70 70 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; 73 73 else name = guid.ToString(); 74 74 } -
branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.Core/DataSetList.cs
r992 r1116 41 41 store = value; 42 42 Action reload = ReloadList; 43 lock (dataSetList) {43 lock (dataSetList) { 44 44 dataSetList.Clear(); 45 45 } … … 58 58 59 59 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) { 62 62 DataSet d = new DataSet(store, s.Subject); 63 lock (dataSetList) {63 lock (dataSetList) { 64 64 dataSetList.Add(d); 65 65 } … … 70 70 public IEnumerator<DataSet> GetEnumerator() { 71 71 List<DataSet> dataSets = new List<DataSet>(); 72 lock (dataSets) {72 lock (dataSets) { 73 73 dataSets.AddRange(dataSetList); 74 74 } -
branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.Core/DataSetView.cs
r1109 r1116 84 84 }; 85 85 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 } 88 93 worker.ReportProgress(100); 89 94 }; -
branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.Core/Results.cs
r1109 r1116 64 64 65 65 private List<ResultsEntry> entries = null; 66 private bool cached = false; 66 67 public IEnumerable<ResultsEntry> GetEntries() { 67 if ( entries == null)68 Reload();68 if (!cached) 69 return SelectRows(); 69 70 return entries.AsEnumerable(); 70 }71 72 internal void Reload() {73 entries = SelectRows().ToList();74 FireChanged();75 71 } 76 72 … … 78 74 if (store == null) yield break; 79 75 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)); 105 77 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); 106 103 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 108 116 foreach (var row in results) { 109 117 ResultsEntry entry = new ResultsEntry(row.First().Model); … … 111 119 entry.Set((string)attr.AttributeName, attr.AttributeValue); 112 120 } 121 entries.Add(entry); 113 122 yield return entry; 114 123 } 124 125 FireChanged(); 126 cached = true; 115 127 } 116 128 … … 120 132 var attributeNames = 121 133 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) 123 135 .Distinct(); 124 136 foreach (var name in attributeNames) { -
branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.DB.Interfaces/HeuristicLab.CEDMA.DB.Interfaces.csproj
r988 r1116 70 70 </ItemGroup> 71 71 <ItemGroup> 72 <Compile Include="IVariableBindings.cs" /> 72 73 <Compile Include="Ontology.cs" /> 73 74 <Compile Include="SelectFilter.cs" /> -
branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.DB.Interfaces/IStore.cs
r551 r1116 35 35 36 36 [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); 41 38 } 42 39 } -
branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.DB/HeuristicLab.CEDMA.DB.csproj
r1041 r1116 74 74 </ItemGroup> 75 75 <ItemGroup> 76 <Compile Include="VariableBindings.cs" /> 76 77 <Compile Include="Store.cs" /> 77 78 <Compile Include="HeuristicLabCedmaDbPlugin.cs" /> -
branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.DB/Store.cs
r957 r1116 42 42 private object bigLock = new object(); 43 43 public Store(string connectionString) { 44 lock (bigLock) {44 lock (bigLock) { 45 45 this.connectionString = connectionString; 46 46 store = SemWeb.Store.Create(connectionString); … … 49 49 50 50 public void Add(Statement statement) { 51 lock (bigLock) {51 lock (bigLock) { 52 52 store.Add(Translate(statement)); 53 53 } 54 54 } 55 55 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; 66 60 } 67 61 68 p ublic 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)); 72 66 } 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; 78 68 } 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 //} 79 86 80 87 private SemWeb.SelectFilter Translate(SelectFilter filter) { … … 91 98 92 99 private SemWeb.Resource Translate(Resource prop) { 93 if (prop is Literal) {100 if (prop is Literal) { 94 101 return TranslateLiteral((Literal)prop); 95 } else if (prop is SerializedLiteral) {102 } else if (prop is SerializedLiteral) { 96 103 return TranslateLiteral((SerializedLiteral)prop); 97 104 } else { … … 101 108 102 109 private Statement Translate(SemWeb.Statement statement) { 103 if (statement.Object is SemWeb.Literal) {110 if (statement.Object is SemWeb.Literal) { 104 111 return new Statement( 105 112 new Entity(statement.Subject.Uri), … … 122 129 123 130 private SemWeb.Literal TranslateLiteral(SerializedLiteral l) { 124 if (l.RawData == null) return null;131 if (l.RawData == null) return null; 125 132 return new SemWeb.Literal(l.RawData, null, "serializedItem"); 126 133 } 127 134 128 135 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); 135 142 else return new SemWeb.Literal(l.Value.ToString()); 136 143 } 137 144 138 145 private Resource TranslateLiteral(SemWeb.Literal l) { 139 if (l.DataType == "serializedItem") {146 if (l.DataType == "serializedItem") { 140 147 return new SerializedLiteral(l.Value); 141 } else if (l.DataType != null) {148 } else if (l.DataType != null) { 142 149 return new Literal(l.ParseValue()); 143 150 } else { -
branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.Server/Dispatcher.cs
r1115 r1116 52 52 private void FillDispatchQueue() { 53 53 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)); 55 55 foreach (Statement datasetStatement in datasetStatements) { 56 56 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)); 58 58 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)); 60 60 foreach (Statement modelAttrStatement in modelAttributeStatements) { 61 61 var targetVariableStatements = store.Select(new Statement((Entity)modelAttrStatement.Property, Ontology.PredicateModelAttributeName, Ontology.AnyEntity)) -
branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.Server/Executer.cs
r1115 r1116 117 117 118 118 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)))); 120 120 121 121 }
Note: See TracChangeset
for help on using the changeset viewer.