001package conexp.fx.core.importer; 002 003/* 004 * #%L 005 * Concept Explorer FX 006 * %% 007 * Copyright (C) 2010 - 2023 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 025 026import java.io.File; 027import java.io.IOException; 028import java.util.HashMap; 029import java.util.Map; 030 031import org.jsoup.Jsoup; 032import org.jsoup.nodes.Element; 033 034import conexp.fx.core.context.MatrixContext; 035import javafx.geometry.Point3D; 036 037public class CEXImporter { 038 039 public static void importt(MatrixContext<String, String> _context, Map<String, Point3D> seedMap, File file) { 040 try { 041 final Element xml = Jsoup.parse(file, null).body(); 042 final Element context = 043 xml 044 .getElementsByTag("ConceptualSystem") 045 .first() 046 .getElementsByTag("Contexts") 047 .first() 048 .getElementsByTag("Context") 049 .first(); 050 final Element attributes = context.getElementsByTag("Attributes").first(); 051 final Element objects = context.getElementsByTag("Objects").first(); 052 final Map<Integer, String> attIdMap = new HashMap<Integer, String>(); 053 for (Element attributeEl : attributes.getElementsByTag("Attribute")) { 054 final Integer id = Integer.valueOf(attributeEl.attr("Identifier")); 055 final String attribute = attributeEl.getElementsByTag("Name").first().text(); 056 attIdMap.put(id, attribute); 057 _context.colHeads().add(attribute); 058 } 059 int i = 0; 060 for (Element objectEl : objects.getElementsByTag("Object")) { 061 final String object = objectEl.getElementsByTag("Name").first().text(); 062 _context.rowHeads().add(object); 063 System.out.println(i++ + "reading object " + object); 064 for (Element hasAttributeEl : objectEl.getElementsByTag("Intent").first().getElementsByTag("HasAttribute")) { 065 _context.addFastSilent(object, attIdMap.get(Integer.valueOf(hasAttributeEl.attr("AttributeIdentifier")))); 066 } 067 } 068// if (seedMap != null) { 069// // TODO extract seed vectors 070// for () { 071// final String attribute = ; 072// final Double x = ; 073// final Double y = ; 074// final Double z = ; 075// final Point3D point3d = new Point3D(x, y, z); 076// seedMap.put(attribute, point3d); 077// } 078// } 079 _context.pushAllChangedEvent(); 080 } catch (IOException e) { 081 // TODO Auto-generated catch block 082 System.err.println("Unable to parse Concept Explorer file from " + file.toString()); 083 e.printStackTrace(); 084 } 085 } 086}