001package conexp.fx.gui.assistent; 002 003/* 004 * #%L 005 * Concept Explorer FX 006 * %% 007 * Copyright (C) 2010 - 2019 Francesco Kriegel 008 * %% 009 * This program is free software: you can redistribute it and/or modify 010 * it under the terms of the GNU General Public License as 011 * published by the Free Software Foundation, either version 3 of the 012 * License, or (at your option) any later version. 013 * 014 * This program is distributed in the hope that it will be useful, 015 * but WITHOUT ANY WARRANTY; without even the implied warranty of 016 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 017 * GNU General Public License for more details. 018 * 019 * You should have received a copy of the GNU General Public 020 * License along with this program. If not, see 021 * <http://www.gnu.org/licenses/gpl-3.0.html>. 022 * #L% 023 */ 024 025import java.util.Arrays; 026 027import org.semanticweb.owlapi.model.IRI; 028import org.semanticweb.owlapi.model.OWLClassExpression; 029 030import conexp.fx.core.builder.Request; 031import conexp.fx.core.builder.Requests.Source; 032import conexp.fx.core.builder.Requests.Type; 033import conexp.fx.core.context.Context; 034import conexp.fx.core.context.MatrixContext; 035import conexp.fx.core.dl.deprecated.Constructor; 036import conexp.fx.gui.ConExpFX; 037import conexp.fx.gui.assistent.InducedContextAssistent.Result; 038import conexp.fx.gui.dataset.DLDataset; 039import conexp.fx.gui.dataset.FCADataset; 040import conexp.fx.gui.task.TimeTask; 041import javafx.collections.FXCollections; 042import javafx.geometry.Insets; 043import javafx.scene.Node; 044import javafx.scene.control.Label; 045import javafx.scene.control.ListView; 046import javafx.scene.control.SelectionMode; 047import javafx.scene.layout.BorderPane; 048import javafx.scene.layout.HBox; 049import javafx.scene.layout.VBox; 050import jfxtras.scene.control.ListSpinner; 051 052public class InducedContextAssistent extends Assistent<Result> { 053 054 public static class Result { 055 056 public Integer selectedRoleDepth; 057 public Integer selectedMaxCardinality; 058 public Constructor[] selectedConstructors; 059 } 060 061 private final DLDataset dataset; 062 private final ListSpinner<Integer> roleDepthSpinner = new ListSpinner<Integer>(0, 3); 063 private final ListSpinner<Integer> maxCardinalitySpinner = new ListSpinner<Integer>(1, 10); 064 private final ListView<Constructor> constructorListView = 065 new ListView<Constructor>(FXCollections.observableList(Arrays.asList(Constructor.values()))); 066 067 public InducedContextAssistent(DLDataset dataset) { 068 super( 069 ConExpFX.instance.primaryStage, 070 "Induced Context Wizard", 071 "Description Logic", 072 "Select Description Logic Constructors", 073 null, 074 r -> null); 075 this.dataset = dataset; 076 initialize(); 077 this.resultProperty.set(new Result()); 078// this.resultProperty.bind(new ObjectBinding<Result>() { 079// 080// { 081// super.bind( 082// roleDepthSpinner.valueProperty(), 083// maxCardinalitySpinner.valueProperty(), 084// constructorListView.getSelectionModel().getSelectedItems()); 085// } 086// 087// @Override 088// protected Result computeValue() { 089// final Result result = new Result(); 090// result.selectedConceptNames = conceptListView.getSelectionModel().getSelectedItems(); 091// result.selectedRoleNames = roleListView.getSelectionModel().getSelectedItems(); 092// result.selectedIsARoleName = isaRoleChoiceBox.getSelectionModel().getSelectedItem(); 093// result.selectedRoleDepth = roleDepthSpinner.getValue(); 094// result.selectedMaxCardinality = maxCardinalitySpinner.getValue(); 095// result.selectedConstructors = constructorListView.getSelectionModel().getSelectedItems().toArray( 096// new Constructor[] {}); 097// return result; 098// } 099// }); 100 } 101 102 @Override 103 protected Node createInitialNode() { 104 final BorderPane pane = new BorderPane(); 105 pane.setPadding(new Insets(4)); 106 roleDepthSpinner.setValue(1); 107 maxCardinalitySpinner.setValue(3); 108 final Label roleDepthLabel = new Label("Role Depth"); 109 roleDepthLabel.setPadding(new Insets(4)); 110 final Label maxCardinalityLabel = new Label("Maximal Cardinality in Number Restrictions"); 111 maxCardinalityLabel.setPadding(new Insets(4)); 112 final Label constructorLabel = new Label("Constructors"); 113 constructorLabel.setPadding(new Insets(4, 4, 1, 4)); 114 roleDepthLabel.setMinWidth(100); 115 maxCardinalityLabel.setMinWidth(100); 116 roleDepthLabel.minWidthProperty().bind(maxCardinalityLabel.widthProperty()); 117 final HBox rbox = new HBox(roleDepthLabel, roleDepthSpinner); 118 final HBox cbox = new HBox(maxCardinalityLabel, maxCardinalitySpinner); 119 final VBox vbox = new VBox(rbox, cbox, constructorLabel, constructorListView); 120 pane.setCenter(vbox); 121 constructorListView.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE); 122 constructorListView.getSelectionModel().select(Constructor.CONJUNCTION); 123 constructorListView.getSelectionModel().select(Constructor.EXISTENTIAL_RESTRICTION); 124 return pane; 125 } 126 127 @Override 128 protected void createPages() {} 129 130 @Override 131 protected void onNext() { 132 this.resultProperty.get().selectedRoleDepth = roleDepthSpinner.getValue(); 133 this.resultProperty.get().selectedMaxCardinality = maxCardinalitySpinner.getValue(); 134 this.resultProperty.get().selectedConstructors = 135 constructorListView.getSelectionModel().getSelectedItems().toArray(new Constructor[] {}); 136 ConExpFX.instance.executor.execute(new TimeTask<Void>("Creating new Induced Context") { 137 138 @Override 139 protected Void call() { 140 updateProgress(0d, 1d); 141 if (isCancelled()) 142 return null; 143 final Context<IRI, OWLClassExpression> inducedContext = dataset.interpretation.getInducedContext( 144 dataset.interpretation.getDomain(), 145 resultProperty.get().selectedRoleDepth, 146 resultProperty.get().selectedMaxCardinality, 147 resultProperty.get().selectedConstructors); 148 ConExpFX.instance.treeView.addDataset( 149 new FCADataset<IRI, OWLClassExpression>( 150 dataset, 151 new Request<IRI, OWLClassExpression>(Type.INDUCED_CONTEXT, Source.NULL) { 152 153 @Override 154 public MatrixContext<IRI, OWLClassExpression> createContext() { 155 MatrixContext<IRI, OWLClassExpression> cxt = new MatrixContext<IRI, OWLClassExpression>(false); 156 return cxt; 157 } 158 159 @Override 160 public void setContent() { 161 this.context.rowHeads().addAll(inducedContext.rowHeads()); 162 this.context.colHeads().addAll(inducedContext.colHeads()); 163 context.addAll(inducedContext); 164 } 165 })); 166 updateProgress(1d, 1d); 167 return null; 168 } 169 }); 170 } 171 172}