001package conexp.fx.gui.context; 002 003//import org.semanticweb.owlapi.apibinding.OWLManager; 004//import org.semanticweb.owlapi.model.OWLClassExpression; 005 006import conexp.fx.core.collections.Collections3; 007import conexp.fx.core.context.Implication; 008import conexp.fx.core.math.GuavaIsomorphism; 009//import conexp.fx.core.util.OWLUtil; 010import conexp.fx.gui.dataset.FCADataset; 011 012/* 013 * #%L 014 * Concept Explorer FX 015 * %% 016 * Copyright (C) 2010 - 2023 Francesco Kriegel 017 * %% 018 * This program is free software: you can redistribute it and/or modify 019 * it under the terms of the GNU General Public License as 020 * published by the Free Software Foundation, either version 3 of the 021 * License, or (at your option) any later version. 022 * 023 * This program is distributed in the hope that it will be useful, 024 * but WITHOUT ANY WARRANTY; without even the implied warranty of 025 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 026 * GNU General Public License for more details. 027 * 028 * You should have received a copy of the GNU General Public 029 * License along with this program. If not, see 030 * <http://www.gnu.org/licenses/gpl-3.0.html>. 031 * #L% 032 */ 033 034import javafx.beans.binding.Bindings; 035import javafx.scene.control.Label; 036import javafx.scene.control.Slider; 037import javafx.scene.control.TableColumnBuilder; 038import javafx.scene.control.TableView; 039import javafx.scene.control.TableViewBuilder; 040import javafx.scene.control.ToolBar; 041import javafx.scene.control.ToolBarBuilder; 042import javafx.scene.layout.BorderPane; 043import javafx.scene.layout.HBox; 044 045@SuppressWarnings({ "deprecation", "unchecked" }) 046public class ImplicationWidget<G, M> extends BorderPane { 047 048 private final FCADataset<G, M> dataset; 049 private final TableView<Implication<G, M>> table; 050 private final ToolBar toolBar; 051 052 public ImplicationWidget(final FCADataset<G, M> dataset) { 053 super(); 054 this.dataset = dataset; 055 final Label confidenceLabel = new Label("Confidence"); 056 final Slider confidenceSlider = new Slider(0, 100, 100); 057 confidenceSlider.setBlockIncrement(5); 058 confidenceSlider.setSnapToTicks(true); 059 confidenceSlider.setMajorTickUnit(1); 060 final Label confidenceValue = new Label(); 061 confidenceValue.textProperty().bind( 062 Bindings 063 .createStringBinding(() -> ((int) confidenceSlider.getValue()) + "%", confidenceSlider.valueProperty())); 064 final HBox confidenceBox = new HBox(confidenceLabel, confidenceSlider, confidenceValue); 065 final Label supportLabel = new Label("Support"); 066 final Slider supportSlider = new Slider(0, 100, 0); 067 supportSlider.setBlockIncrement(5); 068 supportSlider.setSnapToTicks(true); 069 supportSlider.setMajorTickUnit(1); 070 final Label supportValue = new Label(); 071 supportValue.textProperty().bind( 072 Bindings.createStringBinding(() -> ((int) supportSlider.getValue()) + "%", supportSlider.valueProperty())); 073 final HBox supportBox = new HBox(supportLabel, supportSlider, supportValue); 074 this.table = 075 TableViewBuilder 076 .<Implication<G, M>> create() 077 .columns( 078 TableColumnBuilder 079 .<Implication<G, M>, Integer> create() 080 .text("Support") 081 .cellValueFactory(p -> Bindings.createObjectBinding(() -> p.getValue().getSupport().size())) 082 .build(), 083 TableColumnBuilder 084 .<Implication<G, M>, Integer> create() 085 .text("Confidence") 086 .cellValueFactory( 087 p -> Bindings.createObjectBinding(() -> (int) (100d * p.getValue().getConfidence()))) 088 .build(), 089 TableColumnBuilder 090 .<Implication<G, M>, String> create() 091 .text("Premise") 092 .cellValueFactory(p -> Bindings.createObjectBinding(() -> { 093// if (!p.getValue().getPremise().isEmpty() 094// && p.getValue().getPremise().iterator().next() instanceof OWLClassExpression) 095// return OWLUtil.toString( 096// OWLManager.getOWLDataFactory().getOWLObjectIntersectionOf( 097// Collections3.transform( 098// p.getValue().getPremise(), 099// GuavaIsomorphism.create(x -> (OWLClassExpression) x, null)))); 100 return p.getValue().getPremise().toString(); 101 })) 102 .build(), 103 TableColumnBuilder 104 .<Implication<G, M>, String> create() 105 .text("Conclusion") 106 .cellValueFactory(p -> Bindings.createObjectBinding(() -> { 107// if (!p.getValue().getConclusion().isEmpty() 108// && p.getValue().getConclusion().iterator().next() instanceof OWLClassExpression) 109// return OWLUtil.toString( 110// OWLManager.getOWLDataFactory().getOWLObjectIntersectionOf( 111// Collections3.transform( 112// p.getValue().getConclusion(), 113// GuavaIsomorphism.create(x -> (OWLClassExpression) x, null)))); 114 return p.getValue().getConclusion().toString(); 115 })) 116 .build()) 117 .items(dataset.implications) 118 .build(); 119 // TODO: the following line disables sorting functionality when clicking on column heads! 120 table.itemsProperty().bind( 121 Bindings.createObjectBinding( 122 () -> dataset.implications.filtered( 123 impl -> impl.getConfidence() >= confidenceSlider.getValue() / 100d 124 && (int) (100d * (((double) impl.getSupport().size()) 125 / ((double) dataset.context.rowHeads().size()))) >= (int) supportSlider.getValue()), 126 dataset.implications, 127 confidenceSlider.valueProperty(), 128 supportSlider.valueProperty())); 129 this.setCenter(table); 130 this.toolBar = ToolBarBuilder.create().items(supportBox, confidenceBox).build(); 131 this.setTop(toolBar); 132 this.table.getFocusModel().focusedItemProperty().addListener((__, ___, newValue) -> { 133 if (newValue != null) 134 dataset.conceptGraph.highlight(true, dataset.conceptGraph.highlightRequests.implication(newValue)); 135 }); 136 } 137}