001package conexp.fx.gui.context;
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 org.semanticweb.owlapi.apibinding.OWLManager;
026import org.semanticweb.owlapi.model.OWLClassExpression;
027
028import conexp.fx.core.collections.Collections3;
029import conexp.fx.core.context.Concept;
030import conexp.fx.core.math.GuavaIsomorphism;
031import conexp.fx.core.util.OWLUtil;
032import conexp.fx.gui.dataset.FCADataset;
033import javafx.beans.binding.Bindings;
034import javafx.scene.control.TableColumnBuilder;
035import javafx.scene.control.TableView;
036import javafx.scene.control.TableViewBuilder;
037import javafx.scene.layout.BorderPane;
038
039public class ConceptWidget<G, M> extends BorderPane {
040
041  private final FCADataset<G, M>         dataset;
042  private final TableView<Concept<G, M>> table;
043
044  @SuppressWarnings({ "deprecation", "unchecked" })
045  public ConceptWidget(final FCADataset<G, M> dataset) {
046    super();
047    this.dataset = dataset;
048    this.table = TableViewBuilder
049        .<Concept<G, M>> create()
050        .columns(
051            TableColumnBuilder
052                .<Concept<G, M>, Integer> create()
053                .text("Support")
054                .cellValueFactory(p -> Bindings.createObjectBinding(() -> p.getValue().getExtent().size()))
055                .build(),
056            TableColumnBuilder
057                .<Concept<G, M>, Integer> create()
058                .text("Support")
059                .cellValueFactory(
060                    p -> Bindings.createObjectBinding(
061                        () -> (int) ((100d * (double) p.getValue().getExtent().size())
062                            / ((double) dataset.context.rowHeads().size()))))
063                .build(),
064            TableColumnBuilder
065                .<Concept<G, M>, String> create()
066                .text("Extent")
067                .cellValueFactory(p -> Bindings.createObjectBinding(() -> {
068                  final String s = p.getValue().getExtent().toString();
069                  return s.substring(1, s.length() - 1);
070                }))
071                .build(),
072            TableColumnBuilder
073                .<Concept<G, M>, Integer> create()
074                .text("Attributes")
075                .cellValueFactory(p -> Bindings.createObjectBinding(() -> p.getValue().intent().size()))
076                .build(),
077            TableColumnBuilder
078                .<Concept<G, M>, String> create()
079                .text("Intent")
080                .cellValueFactory(p -> Bindings.createObjectBinding(() -> {
081                  if (!p.getValue().getIntent().isEmpty()
082                      && p.getValue().getIntent().iterator().next() instanceof OWLClassExpression)
083                    return OWLUtil.toString(
084                        OWLManager.getOWLDataFactory().getOWLObjectIntersectionOf(
085                            Collections3.transform(
086                                p.getValue().getIntent(),
087                                GuavaIsomorphism.create(x -> (OWLClassExpression) x, null))));
088                  final String s = p.getValue().getIntent().toString();
089                  return s.substring(1, s.length() - 1);
090                }))
091                .build())
092        .items(dataset.concepts)
093        .build();
094    this.setCenter(table);
095  }
096}