Free cookie consent management tool by TermsFeed Policy Generator

Changeset 543


Ignore:
Timestamp:
09/10/08 10:29:28 (16 years ago)
Author:
gkronber
Message:

removed prototypical implementation of rdf-like statement store and corresponding operators in a consolidation step (to prepare for a more solid implementation). Ticket #261 (Items are stored multiple times in the result entries in the CEDMA DB)

Location:
trunk/sources
Files:
5 deleted
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.CEDMA.DB.Interfaces/HeuristicLab.CEDMA.DB.Interfaces.csproj

    r537 r543  
    5555  <ItemGroup>
    5656    <Compile Include="AgentEntry.cs" />
    57     <Compile Include="ItemEntry.cs" />
    5857    <Compile Include="OperatorEntry.cs" />
    5958    <Compile Include="ProcessStatus.cs" />
  • trunk/sources/HeuristicLab.CEDMA.DB.Interfaces/IDatabase.cs

    r537 r543  
    8282    [OperationContract]
    8383    OperatorEntry GetOperator(long id);
    84 
    85     [OperationContract]
    86     IList<ItemEntry> GetOntologyItems();
    87 
    88     [OperationContract]
    89     IList<ItemEntry> GetItems(Guid predicate, Guid property);
    90 
    91     [OperationContract]
    92     void LinkItems(ItemEntry subject, ItemEntry predicate, ItemEntry property);
    9384  }
    9485}
  • trunk/sources/HeuristicLab.CEDMA.DB/Database.cs

    r541 r543  
    6666            using(DbCommand cmd = cnn.CreateCommand()) {
    6767              cmd.CommandText = "CREATE TABLE Operator (ID integer primary key autoincrement, Name text, RawData Blob)";
    68               cmd.Transaction = t;
    69               cmd.ExecuteNonQuery();
    70             }
    71             using(DbCommand cmd = cnn.CreateCommand()) {
    72               cmd.CommandText = "CREATE TABLE Item (guid GUID primary key, RawData Blob)";
    73               cmd.Transaction = t;
    74               cmd.ExecuteNonQuery();
    75             }
    76             using(DbCommand cmd = cnn.CreateCommand()) {
    77               cmd.CommandText = "CREATE TABLE Statement (id integer primary key autoincrement, subject GUID, predicate GUID, property GUID, CreationTime DateTime)";
    7868              cmd.Transaction = t;
    7969              cmd.ExecuteNonQuery();
     
    629619    }
    630620    #endregion
    631 
    632     public IList<ItemEntry> GetOntologyItems() {
    633       List<ItemEntry> ontologies = new List<ItemEntry>();
    634       List<ItemEntry> items = new List<ItemEntry>();
    635       rwLock.EnterReadLock();
    636       try {
    637         using(DbConnection cnn = new SQLiteConnection(connectionString)) {
    638           cnn.Open();
    639           using(DbCommand c = cnn.CreateCommand()) {
    640             c.CommandText = "Select guid, rawdata from Item,(select subject from Statement where subject=property) where subject=guid";
    641             using(DbDataReader r = c.ExecuteReader()) {
    642               while(r.Read()) {
    643                 ItemEntry ontology = new ItemEntry();
    644                 ontology.Guid = r.GetGuid(0);
    645                 ontology.RawData = (byte[])r.GetValue(1);
    646                 ontologies.Add(ontology);
    647               }
    648             }
    649           }
    650           foreach(ItemEntry ontology in ontologies) {
    651             using(DbCommand c = cnn.CreateCommand()) {
    652               c.CommandText = "Select guid, rawdata from Item,(select property from Statement where subject=@ontology) where guid=property";
    653               DbParameter ontologyParam = c.CreateParameter();
    654               ontologyParam.ParameterName = "@ontology";
    655               ontologyParam.Value = ontology.Guid.ToString();
    656               c.Parameters.Add(ontologyParam);
    657               using(DbDataReader r = c.ExecuteReader()) {
    658                 while(r.Read()) {
    659                   ItemEntry item = new ItemEntry();
    660                   item.Guid = r.GetGuid(0);
    661                   item.RawData = (byte[])r.GetValue(1);
    662                   items.Add(item);
    663                 }
    664               }
    665             }
    666           }
    667         }
    668       } finally {
    669         rwLock.ExitReadLock();
    670       }
    671       return items;
    672     }
    673 
    674     public IList<ItemEntry> GetItems(Guid predicate, Guid property) {
    675       List<ItemEntry> items = new List<ItemEntry>();
    676       rwLock.EnterReadLock();
    677       try {
    678         using(DbConnection cnn = new SQLiteConnection(connectionString)) {
    679           cnn.Open();
    680           using(DbCommand c = cnn.CreateCommand()) {
    681             c.CommandText = "Select guid, rawdata from Item,(select subject from Statement where predicate=@Predicate and property=@Property) where subject=guid";
    682             DbParameter predParam = c.CreateParameter();
    683             predParam.ParameterName = "@Predicate";
    684             predParam.Value = predicate.ToString();
    685             c.Parameters.Add(predParam);
    686             DbParameter propertyParam = c.CreateParameter();
    687             propertyParam.ParameterName = "@Property";
    688             propertyParam.Value = property.ToString();
    689             c.Parameters.Add(propertyParam);
    690             using(DbDataReader r = c.ExecuteReader()) {
    691               while(r.Read()) {
    692                 ItemEntry item = new ItemEntry();
    693                 item.Guid = r.GetGuid(0);
    694                 item.RawData = (byte[])r.GetValue(1);
    695                 items.Add(item);
    696               }
    697             }
    698           }
    699         }
    700       } finally {
    701         rwLock.ExitReadLock();
    702       }
    703       return items;
    704     }
    705 
    706     public void LinkItems(ItemEntry subject, ItemEntry predicate, ItemEntry property) {
    707       rwLock.EnterWriteLock();
    708       try {
    709         using(SQLiteConnection cnn = new SQLiteConnection(connectionString)) {
    710           cnn.Open();
    711           using(SQLiteTransaction t = cnn.BeginTransaction()) {
    712             ItemEntry[] items = new ItemEntry[] { subject, predicate, property };
    713             foreach(ItemEntry item in items) {
    714               long n = 0;
    715               using(SQLiteCommand c = cnn.CreateCommand()) {
    716                 c.Transaction = t;
    717                 c.CommandText = "select count(guid) from item where guid=@guid";
    718                 DbParameter guidParam = c.CreateParameter();
    719                 guidParam.ParameterName = "@guid";
    720                 guidParam.Value = item.Guid.ToString();
    721                 c.Parameters.Add(guidParam);
    722                 n = (long)c.ExecuteScalar();
    723               }
    724               if(n == 0) using(SQLiteCommand c = cnn.CreateCommand()) {
    725                   c.Transaction = t;
    726                   c.CommandText = "insert into item (Guid, RawData) values (@Guid, @RawData)";
    727                   DbParameter guidParam = c.CreateParameter();
    728                   guidParam.ParameterName = "@Guid";
    729                   guidParam.Value = item.Guid.ToString();
    730                   c.Parameters.Add(guidParam);
    731                   DbParameter rawDataParam = c.CreateParameter();
    732                   rawDataParam.ParameterName = "@RawData";
    733                   rawDataParam.Value = item.RawData;
    734                   c.Parameters.Add(rawDataParam);
    735                   c.ExecuteNonQuery();
    736                 }
    737             }
    738             using(SQLiteCommand c = cnn.CreateCommand()) {
    739               c.Transaction = t;
    740               c.CommandText = "insert into Statement (Subject, Predicate, Property, CreationTime) values (@Subject, @Predicate, @Property, @CreationTime)";
    741               DbParameter subjectParam = c.CreateParameter();
    742               subjectParam.ParameterName = "@Subject";
    743               subjectParam.Value = subject.Guid.ToString();
    744               c.Parameters.Add(subjectParam);
    745               DbParameter predParam = c.CreateParameter();
    746               predParam.ParameterName = "@Predicate";
    747               predParam.Value = predicate.Guid.ToString();
    748               c.Parameters.Add(predParam);
    749               DbParameter propertyParam = c.CreateParameter();
    750               propertyParam.ParameterName = "@Property";
    751               propertyParam.Value = property.Guid.ToString();
    752               c.Parameters.Add(propertyParam);
    753               DbParameter timeParam = c.CreateParameter();
    754               timeParam.ParameterName = "@CreationTime";
    755               timeParam.Value = DateTime.Now;
    756               c.Parameters.Add(timeParam);
    757               c.ExecuteNonQuery();
    758             }
    759             t.Commit();
    760           }
    761         }
    762       } finally {
    763         rwLock.ExitWriteLock();
    764       }
    765     }
    766621  }
    767622}
  • trunk/sources/HeuristicLab.CEDMA.Operators/HeuristicLab.CEDMA.Operators.csproj

    r542 r543  
    5454  </ItemGroup>
    5555  <ItemGroup>
    56     <Compile Include="VariableExtractor.cs" />
    57     <Compile Include="SubScopesExtractor.cs" />
    58     <Compile Include="OntologyExtractor.cs" />
    5956    <Compile Include="ResultsExtractor.cs" />
    60     <Compile Include="MakeStatement.cs" />
    6157    <Compile Include="InjectedVariableExtractor.cs" />
    6258    <Compile Include="SplitScopeToItemsResultWriter.cs" />
  • trunk/sources/HeuristicLab.CEDMA.Server/HeuristicLab.CEDMA.Server.csproj

    r419 r543  
    44    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    55    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
    6     <ProductVersion>9.0.21022</ProductVersion>
     6    <ProductVersion>9.0.30729</ProductVersion>
    77    <SchemaVersion>2.0</SchemaVersion>
    88    <ProjectGuid>{F05D261A-4F7D-46C9-AB9C-21FD4566D719}</ProjectGuid>
  • trunk/sources/HeuristicLab.CEDMA.Server/ServerForm.cs

    r540 r543  
    7070        database = new Database(connectionString);
    7171        database.CreateNew();
    72         InitDefaultOntology();
    7372      } else {
    7473        database = new Database(connectionString);
    75         if(database.GetOntologyItems().Count == 0) InitDefaultOntology();
    7674      }
    77     }
    78 
    79     private void InitDefaultOntology() {
    80       // init default ontology
    81       StringData[] entities = new StringData[] {
    82       new StringData("CedmaOntology"),
    83       new StringData("definesEntity"),
    84       new StringData("class:GpFunctionTree"),
    85       new StringData("class:Dataset"),
    86       new StringData("instanceOf"),
    87       new StringData("hasModel"),
    88       new StringData("modelOf"),
    89       new StringData("targetVariable"),
    90       new StringData("trainingSamplesStart"),
    91       new StringData("trainingSamplesEnd"),
    92       new StringData("validationSamplesStart"),
    93       new StringData("validationSamplesEnd"),
    94       new StringData("testSamplesStart"),
    95       new StringData("testSamplesEnd"),
    96       new StringData("trainingMeanSquaredError"),
    97       new StringData("validationMeanSquaredError"),
    98       new StringData("testMeanSquaredError"),
    99       new StringData("trainingMeanAbsolutePercentageError"),
    100       new StringData("validationMeanAbsolutePercentageError"),
    101       new StringData("testMeanAbsolutePercentageError"),
    102       new StringData("treeSize"),
    103       new StringData("treeHeight")
    104       };
    105       foreach(StringData entity in entities) {
    106         LinkItems(entities[0], entities[1], entity);
    107       }
    108     }
    109 
    110     private void LinkItems(StringData subj, StringData pred, StringData prop) {
    111       ItemEntry subjEntry = new ItemEntry();
    112       ItemEntry predEntry = new ItemEntry();
    113       ItemEntry propEntry = new ItemEntry();
    114       subjEntry.Guid = subj.Guid;
    115       subjEntry.RawData = PersistenceManager.SaveToGZip(subj);
    116       predEntry.Guid = pred.Guid;
    117       predEntry.RawData = PersistenceManager.SaveToGZip(pred);
    118       propEntry.Guid = prop.Guid;
    119       propEntry.RawData = PersistenceManager.SaveToGZip(prop);
    120 
    121       database.LinkItems(subjEntry, predEntry, propEntry);
    12275    }
    12376
Note: See TracChangeset for help on using the changeset viewer.