Free cookie consent management tool by TermsFeed Policy Generator

source: branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.Core/Results.cs @ 1109

Last change on this file since 1109 was 1109, checked in by gkronber, 15 years ago

worked on presentation layer for CEDMA (brushing) (#419)

File size: 4.1 KB
RevLine 
[560]1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2008 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System;
23using System.Collections.Generic;
24using System.Linq;
25using System.Text;
26using HeuristicLab.Core;
27using System.Collections;
28using HeuristicLab.CEDMA.DB.Interfaces;
29using System.Xml;
30using System.Runtime.Serialization;
31using System.IO;
[562]32using HeuristicLab.PluginInfrastructure;
[567]33using HeuristicLab.Data;
34using HeuristicLab.DataAnalysis;
35using System.Drawing;
[560]36
[1073]37namespace HeuristicLab.CEDMA.Core {
[1109]38  public class Results : ItemBase {
[1106]39    public static string[] CategoricalVariables {
40      get { return new string[] { "TargetVariable" }; }
41    }
[560]42
[1106]43    public static string[] OrdinalVariables {
44      get { return new string[] { "ValidationMeanAbsolutePercentageError" }; }
45    }
46
[560]47    private IStore store;
48    public IStore Store {
49      get { return store; }
50      set {
51        store = value;
52      }
53    }
[561]54
[1106]55    private Entity dataSetEntity;
[560]56
[1106]57    public Results(IStore store) {
[1075]58      this.store = store;
[560]59    }
60
[1106]61    internal void FilterDataSet(Entity entity) {
62      this.dataSetEntity = entity;
[560]63    }
64
[1109]65    private List<ResultsEntry> entries = null;
66    public IEnumerable<ResultsEntry> GetEntries() {
67      if (entries == null)
68        Reload();
69      return entries.AsEnumerable();
70    }
71
72    internal void Reload() {
73      entries = SelectRows().ToList();
74      FireChanged();
75    }
76
77    private IEnumerable<ResultsEntry> SelectRows() {
[1108]78      if (store == null) yield break;
[567]79
[1106]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 },
[1108]90              new Entity[] { Ontology.AnyEntity })).Select(y =>
[1106]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
[1108]104               })).GroupBy(x => x.Model);
[1075]105
106
[1106]107      Random random = new Random();
108      foreach (var row in results) {
[1108]109        ResultsEntry entry = new ResultsEntry(row.First().Model);
110        foreach (var attr in row) {
111          entry.Set((string)attr.AttributeName, attr.AttributeValue);
112        }
113        yield return entry;
114      }
115    }
[1075]116
[1108]117    internal IEnumerable<string> SelectModelAttributes() {
118      if (store == null) yield break;
119
120      var attributeNames =
121        store.Select(new Statement(Ontology.AnyEntity, Ontology.PredicateModelAttributeName, Ontology.AnyEntity))
122        .Select(s => (string)((Literal)s.Property).Value)
123        .Distinct();
124      foreach (var name in attributeNames) {
125        yield return name;
[1106]126      }
[560]127    }
128  }
129}
Note: See TracBrowser for help on using the repository browser.