📄 ontology.java
字号:
/* * YALE - Yet Another Learning Environment * Copyright (C) 2002, 2003 * Simon Fischer, Ralf Klinkenberg, Ingo Mierswa, * Katharina Morik, Oliver Ritthoff * Artificial Intelligence Unit * Computer Science Department * University of Dortmund * 44221 Dortmund, Germany * email: yale@ls8.cs.uni-dortmund.de * web: http://yale.cs.uni-dortmund.de/ * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * USA. */package edu.udo.cs.yale.tools;/** Very simple ontology class. Two static ontologies are available: * <tt>ATTRIBUTE_BLOCK_TYPE</tt> and <tt>ATTRIBUTE_VALUE_TYPE</tt>. * It provides a single method <tt>boolean isA(int sub, int super)</tt> which * does what isA-methods are usually expected to do. Legal parameters are * the constants. * @version $Id: Ontology.java,v 2.3 2003/06/29 14:40:43 mierswa Exp $ */public class Ontology { public static final int VALUE_TYPE = 0; public static final int BLOCK_TYPE = 1; /** The parent's index in the array. Root has parent -1. */ private int parentId[]; /** Human readable string representations. */ private String names[]; public static final int NO_PARENT = -1; // -------------------- VALUE TYPE -------------------- public static final int ATTRIBUTE_VALUE = 0; public static final int NOMINAL = 1; public static final int NUMERICAL = 2; public static final int INTEGER = 3; public static final int REAL = 4; public static final int ORDERED = 5; public static final int CLUSTER = 6; public static final int CLASSIFICATION = 7; // nominal, only +1 and -1 public static final int BOOLEAN = 8; public static final int FILE_PATH = 9; // path to a file private static final String[] VALUE_TYPE_NAMES = { "attribute_value", "nominal", "numeric", "integer", "real", "ordered", "cluster", "classification", "boolean", "file_path" }; /** An ontology for value types (nominal, numerical...) */ public static final Ontology ATTRIBUTE_VALUE_TYPE = new Ontology( new int[] { NO_PARENT, ATTRIBUTE_VALUE, ATTRIBUTE_VALUE, NUMERICAL, NUMERICAL, NOMINAL, NOMINAL, NOMINAL, NOMINAL, NOMINAL}, VALUE_TYPE_NAMES); // -------------------- BLOCK TYPE -------------------- public static final int ATTRIBUTE_BLOCK = 0; public static final int VALUE_SERIES = 1; public static final int NON_SERIES = 2; public static final int SINGLE_VALUE = 3; public static final int INTERVAL = 4; public static final int X = 5; public static final int Y = 6; public static final int VALUE_SERIES_START = 7; public static final int VALUE_SERIES_END = 8; public static final int INTERVAL_START = 9; public static final int INTERVAL_END = 10; private static final String[] BLOCK_TYPE_NAMES = { "attribute_block", "value_series", "non_series", "single_value", "interval", "x", "y", "value_series_start", "value_series_end", "interval_start", "interval_end" }; /** An ontology for block types (single, time series...) */ public static final Ontology ATTRIBUTE_BLOCK_TYPE = new Ontology( new int[] { NO_PARENT, ATTRIBUTE_BLOCK, ATTRIBUTE_BLOCK, NON_SERIES, NON_SERIES, SINGLE_VALUE, SINGLE_VALUE, VALUE_SERIES, VALUE_SERIES, INTERVAL, INTERVAL }, BLOCK_TYPE_NAMES); /** Constructs a new ontology where each of the entries points to its parent. */ private Ontology(int[] parents, String[] names) { this.parentId = parents; this.names = names; } /** Returns true if child is a parent. */ public boolean isA(int child, int parent) { while (child != parent) { child = parentId[child]; if (child == -1) return false; } return true; } /** Maps the name of a class to its index or -1 if unknown. */ public int mapName(String name) { for (int i = 0 ; i < names.length; i++) { if (names[i].equals(name)) return i; } return -1; } /** Maps an index to its name. */ public String mapIndex(int index) { if ((index >= 0) && (index < names.length)) return names[index]; else return null; } public String[] getNames() { return names; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -