⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 relation.java

📁 图像检索的代码b
💻 JAVA
字号:
package at.lux.fotoretrieval.lucene;

import java.util.HashMap;
import java.text.DecimalFormat;

/*
 * This file is part of Caliph & Emir.
 *
 * Caliph & Emir 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.
 *
 * Caliph & Emir 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 Caliph & Emir; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 * Copyright statement:
 * --------------------
 * (c) 2002-2004 by Mathias Lux (mathias@juggle.at) and the Know-Center Graz
 * Inffeldgasse 21a, 8010 Graz, Austria
 * http://www.know-center.at
 */

/**
 * Date: 29.10.2004
 * Time: 23:57:34
 *
 * @author Mathias Lux, mathias@juggle.at
 */
public class Relation implements Comparable {
    private int source, target;
    private String type;
    private static HashMap<String, String> relationMapping;

    static {
        relationMapping = new HashMap<String, String>(27);
        relationMapping.put("key", "keyFor");
        relationMapping.put("annotates", "annotatedBy");
        relationMapping.put("shows", "appearsIn");
        relationMapping.put("references", "referencedBy");
        relationMapping.put("quality", "qualityOf");
        relationMapping.put("symbolizes", "symbolizedBy");
        relationMapping.put("location", "locationOf");
        relationMapping.put("source", "sourceOf");
        relationMapping.put("destination", "destinationOf");
        relationMapping.put("path", "pathOf");
        relationMapping.put("time", "timeOf");
        relationMapping.put("depicts", "depictedBy");
        relationMapping.put("represents", "representedBy");
        relationMapping.put("context", "contextFor");
        relationMapping.put("interprets", "interpretedBy");
        relationMapping.put("agent", "agentOf");
        relationMapping.put("patient", "patientOf");
        relationMapping.put("experiencer", "experiencerOf");
        relationMapping.put("stimulus", "stimulusOf");
        relationMapping.put("causer", "causerOf");
        relationMapping.put("goal", "goalOf");
        relationMapping.put("beneficiary", "beneficiaryOf");
        relationMapping.put("theme", "themeOf");
        relationMapping.put("result", "resultOf");
        relationMapping.put("instrument", "instrumentOf");
        relationMapping.put("accompanier", "accompanierOf");
        relationMapping.put("summarizes", "summarizedBt");
        relationMapping.put("specializes", "generalizes");
        relationMapping.put("exemplifies", "exemplifiedBy");
        relationMapping.put("part", "partOf");
        relationMapping.put("property", "propertyOf");
        relationMapping.put("user", "userOf");
        relationMapping.put("component", "componentOf");
        relationMapping.put("substance", "substanceOf");
        relationMapping.put("entails", "entailedBy");
        relationMapping.put("manner", "mannerOf");
        relationMapping.put("state", "stateOf");
        relationMapping.put("influences", "dependsOn");
    }


    /**
     * Creates a new Relation with given source, target and name
     * @param source defines the node ID of the source
     * @param target defines the node ID of the target
     * @param type
     */
    public Relation(int source, int target, String type) {
        this.source = source;
        this.target = target;
        this.type = type;
    }

    public int getSource() {
        return source;
    }

    public int getTarget() {
        return target;
    }

    public String getType() {
        return type;
    }

    public void setSource(int source) {
        this.source = source;
    }

    public void setTarget(int target) {
        this.target = target;
    }

    public void setType(String type) {
        this.type = type;
    }

    public String toString() {
        DecimalFormat df = (DecimalFormat) DecimalFormat.getInstance();
        df.setMinimumIntegerDigits(5);
        df.setMaximumFractionDigits(0);
        df.setGroupingUsed(false);
        return (type + " " + df.format(source) + " " + df.format(target));
    }

    public boolean isSourceOrTarget(int nodeID) {
        boolean result = false;
        if (source == nodeID || target == nodeID) result = true;
        return result;
    }

    public int compareTo(Object o) {
        String s = ((Relation) o).toString();
        return (toString().compareTo(s));
    }

    public Relation clone() {
        return new Relation(source, target, new String(type));
    }

    /**
     * eliminates an inverse relation as there is an inverse
     * defined for each possible relation.
     */
    public void eliminateInverse() {
        if (relationMapping.containsKey(type)) {
            type = relationMapping.get(type);
            int tmp = source;
            source = target;
            target = tmp;
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -