[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 |
|
---|
| 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;
|
---|
[562] | 32 | using HeuristicLab.PluginInfrastructure;
|
---|
[567] | 33 | using HeuristicLab.Data;
|
---|
| 34 | using HeuristicLab.DataAnalysis;
|
---|
| 35 | using System.Drawing;
|
---|
[560] | 36 |
|
---|
[1073] | 37 | namespace HeuristicLab.CEDMA.Core {
|
---|
[1109] | 38 | public class Results : ItemBase {
|
---|
[1151] | 39 | private string[] categoricalVariables = null;
|
---|
| 40 | public string[] CategoricalVariables {
|
---|
| 41 | get {
|
---|
| 42 | if (categoricalVariables == null) {
|
---|
| 43 | LoadModelAttributes();
|
---|
| 44 | }
|
---|
| 45 | return categoricalVariables;
|
---|
| 46 | }
|
---|
[1106] | 47 | }
|
---|
[560] | 48 |
|
---|
[1151] | 49 | private string[] ordinalVariables = null;
|
---|
| 50 | public string[] OrdinalVariables {
|
---|
| 51 | get {
|
---|
| 52 | if (ordinalVariables == null) {
|
---|
| 53 | LoadModelAttributes();
|
---|
| 54 | }
|
---|
| 55 | return ordinalVariables;
|
---|
| 56 | }
|
---|
[1106] | 57 | }
|
---|
| 58 |
|
---|
[560] | 59 | private IStore store;
|
---|
| 60 | public IStore Store {
|
---|
| 61 | get { return store; }
|
---|
| 62 | set {
|
---|
| 63 | store = value;
|
---|
| 64 | }
|
---|
| 65 | }
|
---|
[561] | 66 |
|
---|
[1106] | 67 | private Entity dataSetEntity;
|
---|
[560] | 68 |
|
---|
[1106] | 69 | public Results(IStore store) {
|
---|
[1075] | 70 | this.store = store;
|
---|
[560] | 71 | }
|
---|
| 72 |
|
---|
[1106] | 73 | internal void FilterDataSet(Entity entity) {
|
---|
| 74 | this.dataSetEntity = entity;
|
---|
[560] | 75 | }
|
---|
| 76 |
|
---|
[1109] | 77 | private List<ResultsEntry> entries = null;
|
---|
[1116] | 78 | private bool cached = false;
|
---|
[1109] | 79 | public IEnumerable<ResultsEntry> GetEntries() {
|
---|
[1116] | 80 | if (!cached)
|
---|
| 81 | return SelectRows();
|
---|
[1109] | 82 | return entries.AsEnumerable();
|
---|
| 83 | }
|
---|
| 84 |
|
---|
| 85 | private IEnumerable<ResultsEntry> SelectRows() {
|
---|
[1108] | 86 | if (store == null) yield break;
|
---|
[1151] | 87 | entries = new List<ResultsEntry>();
|
---|
[1156] | 88 | var results = store.Query("<" + dataSetEntity + "> <" + Ontology.PredicateHasModel + "> ?Model ." + Environment.NewLine +
|
---|
[1151] | 89 | "?Model ?Attribute ?Value .")
|
---|
[1156] | 90 | .GroupBy(x => (Entity)x.Get("Model"));
|
---|
[1151] | 91 | foreach (var modelBindings in results) {
|
---|
| 92 | ResultsEntry entry = new ResultsEntry(modelBindings.Key.Uri);
|
---|
| 93 | foreach (var binding in modelBindings) {
|
---|
| 94 | if (binding.Get("Value") is Literal) {
|
---|
| 95 | string name = ((Entity)binding.Get("Attribute")).Uri.Replace(Ontology.CedmaNameSpace, "");
|
---|
| 96 | if (entry.Get(name) == null) {
|
---|
| 97 | object value = ((Literal)binding.Get("Value")).Value;
|
---|
| 98 | entry.Set(name, value);
|
---|
| 99 | }
|
---|
| 100 | }
|
---|
| 101 | }
|
---|
| 102 | entries.Add(entry);
|
---|
| 103 | yield return entry;
|
---|
| 104 | }
|
---|
[567] | 105 |
|
---|
[1151] | 106 | FireChanged();
|
---|
| 107 | cached = true;
|
---|
[1108] | 108 | }
|
---|
[1075] | 109 |
|
---|
[1108] | 110 | internal IEnumerable<string> SelectModelAttributes() {
|
---|
[1151] | 111 | return CategoricalVariables.Concat(OrdinalVariables);
|
---|
| 112 | }
|
---|
[1108] | 113 |
|
---|
[1151] | 114 | private void LoadModelAttributes() {
|
---|
| 115 | this.ordinalVariables =
|
---|
| 116 | store.Query("?ModelAttribute <" + Ontology.PredicateInstanceOf + "> <" + Ontology.TypeOrdinalAttribute + "> .")
|
---|
| 117 | .Select(s => ((Entity)s.Get("ModelAttribute")).Uri.Replace(Ontology.CedmaNameSpace, ""))
|
---|
| 118 | .ToArray();
|
---|
| 119 | this.categoricalVariables =
|
---|
| 120 | store.Query("?ModelAttribute <" + Ontology.PredicateInstanceOf + "> <" + Ontology.TypeCategoricalAttribute + "> .")
|
---|
| 121 | .Select(s => ((Entity)s.Get("ModelAttribute")).Uri.Replace(Ontology.CedmaNameSpace, ""))
|
---|
| 122 | .ToArray();
|
---|
[560] | 123 | }
|
---|
| 124 | }
|
---|
| 125 | }
|
---|