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 |
|
---|
22 | using System;
|
---|
23 | using System.Collections.Generic;
|
---|
24 | using System.Linq;
|
---|
25 | using System.Text;
|
---|
26 | using HeuristicLab.Core;
|
---|
27 | using System.Collections;
|
---|
28 | using HeuristicLab.CEDMA.DB.Interfaces;
|
---|
29 | using System.Xml;
|
---|
30 | using System.Runtime.Serialization;
|
---|
31 | using System.IO;
|
---|
32 | using HeuristicLab.PluginInfrastructure;
|
---|
33 | using HeuristicLab.Data;
|
---|
34 | using HeuristicLab.DataAnalysis;
|
---|
35 | using System.Drawing;
|
---|
36 |
|
---|
37 | namespace HeuristicLab.CEDMA.Core {
|
---|
38 | public class Results : ItemBase {
|
---|
39 | public static string[] CategoricalVariables {
|
---|
40 | get { return new string[] { "TargetVariable" }; }
|
---|
41 | }
|
---|
42 |
|
---|
43 | public static string[] OrdinalVariables {
|
---|
44 | get { return new string[] { "ValidationMeanAbsolutePercentageError" }; }
|
---|
45 | }
|
---|
46 |
|
---|
47 | private IStore store;
|
---|
48 | public IStore Store {
|
---|
49 | get { return store; }
|
---|
50 | set {
|
---|
51 | store = value;
|
---|
52 | }
|
---|
53 | }
|
---|
54 |
|
---|
55 | private Entity dataSetEntity;
|
---|
56 |
|
---|
57 | public Results(IStore store) {
|
---|
58 | this.store = store;
|
---|
59 | }
|
---|
60 |
|
---|
61 | internal void FilterDataSet(Entity entity) {
|
---|
62 | this.dataSetEntity = entity;
|
---|
63 | }
|
---|
64 |
|
---|
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() {
|
---|
78 | if (store == null) yield break;
|
---|
79 |
|
---|
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);
|
---|
105 |
|
---|
106 |
|
---|
107 | Random random = new Random();
|
---|
108 | foreach (var row in results) {
|
---|
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 | }
|
---|
116 |
|
---|
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;
|
---|
126 | }
|
---|
127 | }
|
---|
128 | }
|
---|
129 | }
|
---|