亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來(lái)到蟲(chóng)蟲(chóng)下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲(chóng)蟲(chóng)下載站

?? example06.java

?? 本體推理工具 共八個(gè)例子:從如何建立本體到做一些簡(jiǎn)單的的本體推理
?? JAVA
字號(hào):
package ex06;

import java.io.*;
import java.util.*;

import org.semanticweb.kaon2.api.*;
import org.semanticweb.kaon2.api.logic.*;
import org.semanticweb.kaon2.api.owl.elements.*;
import org.semanticweb.kaon2.api.formatting.*;
import org.semanticweb.kaon2.api.reasoner.*;

import org.semanticweb.kaon2.extensionapi.datatype.*;
import org.semanticweb.kaon2.extensionapi.builtins.*;

/**
 * This example explains how to extend KAON2 with new datatypes and with new builtin functions.
 */
public class Example06 {
    public static void main(String[] args) throws Exception {
        // Imagine you want to introduce a new datatype, Currency, whose values consist of a
        // (amount, code) pair. KAON2 does not have function symbols, so you can't represent
        // this data structure as you might do it in Prolog. However, KAON2 can do better.
        // In particular, you can introduce a class Currency, which will represent new data values.
        // Also, you can extend the reasoning facilities of KAON2 with new functions that operate on these values.
        //
        // The first step in doing so is to acutally create a class that will represent currency objects.
        // The class is defined after this method. It can have an arbitrary form. However, in most
        // cases, the class should have "value" semantics, i.e., objects of the class should be immutable,
        // and one should implement equals() and hashCode(). The reason for this is that KAON2 compares all
        // objects using equals(), and stores objects in internal maps using hashCode(). If an object is stored
        // in an internal map, but the object is changed so that its hashcode is also changed, the behavior
        // of KAON2 inferences is not defined. Alternatively, the objects might have "reference" semantics,
        // i.e., each object is equal only to itself. It is up to you then to ensure such semantics.
        //
        // After providing the class for the actual data value, one must register the so-called handler
        // for the datatype. The handler is responsible for loading and storing datatype objects into files.
        // Refer to the definition of CurrencyHandler class for more information.
        Datatypes.registerDatatypeHandler(new CurrencyHandler());

        KAON2Connection connection=KAON2Manager.newConnection();
        DefaultOntologyResolver resolver=new DefaultOntologyResolver();
        resolver.registerReplacement("http://kaon2.semanticweb.org/example06","file:example06.xml");
        connection.setOntologyResolver(resolver);
        Ontology ontology=connection.createOntology("http://kaon2.semanticweb.org/example06",new HashMap<String,Object>());

        List<OntologyChangeEvent> changes=new ArrayList<OntologyChangeEvent>();

        // We can now use the new datatype. For example, we now specify some information about Smart cars
        // (the small cars by DaimlerChrysler).
        OWLClass car=KAON2Manager.factory().owlClass("http://kaon2.semanticweb.org/example06#car");
        Individual smart=KAON2Manager.factory().individual("http://kaon2.semanticweb.org/example06#smart");
        DataProperty price=KAON2Manager.factory().dataProperty("http://kaon2.semanticweb.org/example06#price");

        // Smart is a car.
        changes.add(new OntologyChangeEvent(KAON2Manager.factory().classMember(car,smart),OntologyChangeEvent.ChangeType.ADD));

        // We now say that smart costs 9000 EUR. Notice that we use the newly created Currency object here.
        changes.add(new OntologyChangeEvent(KAON2Manager.factory().dataPropertyMember(price,smart,KAON2Manager.factory().constant(new Currency(9000,"EUR"))),OntologyChangeEvent.ChangeType.ADD));

        // We add these facts to the ontolgoy.
        ontology.applyChanges(changes);

        // We now save the ontology to C:\Temp. You may open the file to assure yourself that the Currency datatype has been property saved.
        System.out.println("The ontology will be saved into 'c:\\temp\\example06.xml'.");
        System.out.println("Please ensure that 'c:\\temp' directory exists.");
        ontology.saveOntology(OntologyFileFormat.OWL_XML,new File("c:\\temp\\example06.xml"),"ISO-8859-1");

        System.out.println("The ontology was saved successfully into 'c:\\temp\\example06.xml'.");

        // Let us now retrieve the prices or all cars, but in USD. To do this, we implement a new builtin function,
        // which performs the conversion of currencies. Each function is implemented in a sperate class. Please refer
        // to the documentation of the CurrencyConversion class for more information. We register this new builin function
        // as specified below. The first parameter is the name of the function (which will be used in the kaon:evaluate and
        // kaon2:ifTrue expressions), and the second parameter is the actual class.
        ExpressionEvaluator.registerBuiltinFunction("convert",CurrencyConversion.class);

        // We can now create the literal that performs the conversion from any price to a price in USD.
        Variable PRICE_ANY=KAON2Manager.factory().variable("PRICE_ANY");
        Variable PRICE_USD=KAON2Manager.factory().variable("PRICE_USD");
        Literal conversion=KAON2Manager.factory().literal(true,KAON2Manager.factory().evaluate(3),new Term[] {
            KAON2Manager.factory().constant("convert($1,\"USD\")"),
            PRICE_ANY,
            PRICE_USD
        });

        // We now create the query.
        Reasoner reasoner=ontology.createReasoner();
        Variable CAR=KAON2Manager.factory().variable("CAR");
        Query inUSD=reasoner.createQuery(new Literal[] {
            KAON2Manager.factory().literal(true,car,new Term[] { CAR }),
            KAON2Manager.factory().literal(true,price,new Term[] { CAR,PRICE_ANY }),
            conversion
        },new Variable[] { CAR,PRICE_USD });

        System.out.println("Cars and their prices:");
        System.out.println("----------------------");

        inUSD.open();
        while (!inUSD.afterLast()) {
            Term[] tupleBuffer=inUSD.tupleBuffer();
            System.out.println("'"+tupleBuffer[0].toString()+"' costs "+tupleBuffer[1].toString());
            inUSD.next();
        }
        inUSD.close();
        inUSD.dispose();

        System.out.println("-----------------------");

        // You can call the new functions from SPARQL. The functions can be called either in the FILTER clause, or in a proprietary EVALUATE clause.
        
        inUSD=reasoner.createQuery(new Namespaces(Namespaces.INSTANCE),
            "PREFIX a: <http://kaon2.semanticweb.org/example06#> "+
            "SELECT ?CAR ?PRICE_USD WHERE { ?CAR rdf:type a:car . ?CAR a:price ?PRICE_ANY . EVALUATE ?PRICE_USD := convert(?PRICE_ANY,\"USD\") }");
        
        System.out.println("Cars and their prices from SPARQL:");
        System.out.println("----------------------------------");

        inUSD.open();
        while (!inUSD.afterLast()) {
            Term[] tupleBuffer=inUSD.tupleBuffer();
            System.out.println("'"+tupleBuffer[0].toString()+"' costs "+tupleBuffer[1].toString());
            inUSD.next();
        }
        inUSD.close();
        inUSD.dispose();

        System.out.println("----------------------------------");

        // Do not forget to celan up!
        reasoner.dispose();
        connection.close();
    }

    /**
     * The class representing a currency value.
     */
    protected static class Currency {
        protected final double m_amount;
        protected final String m_code;

        public Currency(double amount,String code) {
            m_amount=amount;
            m_code=code;
        }
        public double getAmount() {
            return m_amount;
        }
        public String getCode() {
            return m_code;
        }
        public boolean equals(Object that) {
            if (this==that)
                return true;
            if (!(that instanceof Currency))
                return false;
            Currency thatCurrency=(Currency)that;
            return m_amount==thatCurrency.m_amount && m_code.equals(thatCurrency.m_code);
        }
        public int hashCode() {
            return m_code.hashCode()+(int)m_amount;
        }
        public String toString() {
            return m_amount+" "+m_code;
        }
    }

    /**
     * Implements a handler for Currency objects. The handler is mainly reponsible for loading and storing
     * object instances in files. Also, the handler probvides a URI for the datatype.
     */
    protected static class CurrencyHandler implements DatatypeHandler {
        public boolean isDatatypeInstance(Object object) {
            // This method should determine whether the supplied object is an instance of the given datatype.
            return object instanceof Currency;
        }
        public String getDatatypeURI() {
            // Each datatype has an URI, which is used in OWL files to denote the type of the value.
            // Here, we simply invent a new URI.
            return "http://kaon2.semanticweb.org/example06#Currency";
        }
        public int getArity() {
            // This method determines the arity of this datatype.
            return 1;
        }
        public String toString(Object object) {
            // This method produces a string representation of the object.
            return object.toString();
        }
        public Object parseObject(String objectValue) throws KAON2Exception {
            // This method converts the string representation of the object into an actual object.
            int spaceIndex=objectValue.indexOf(' ');
            if (spaceIndex!=-1) {
                String amountString=objectValue.substring(0,spaceIndex).trim();
                String code=objectValue.substring(spaceIndex+1).trim();
                try {
                    double amount=Double.parseDouble(amountString);
                    return new Currency(amount,code);
                }
                catch (NumberFormatException e) {
                }
            }
            throw new KAON2Exception("Invalid currency '"+objectValue+"'.");
        }

    }

    /**
     * Implements a builtin function for conversion of currencies. In expressions, this function
     * is called as convert(cur,to_code), where cur is the expression having Currency as result,
     * and to_code is the code of the currency to which conversion is performed.
     */
    protected static class CurrencyConversion extends ExpressionEvaluator {
        protected static final Map<String,Double> s_currencyToEUR;
        static {
            s_currencyToEUR=new HashMap<String,Double>();
            s_currencyToEUR.put("EUR",1.0);
            s_currencyToEUR.put("USD",0.8);
            s_currencyToEUR.put("GBP",1.3);
        }

        protected final ExpressionEvaluator[] m_arguments;

        /**
         * A builtin function should have a public constructor receiving
         * ExpressionEvaluator... as parameters. These evaluators will
         * produce the values of function arguments.
         *
         * @param arguments                     the evaluators producing arguments for this function
         */
        public CurrencyConversion(ExpressionEvaluator... arguments) {
            m_arguments=arguments;
        }
        /**
         * This method will be called to evaluate the function. The arguments of the kaon2:evaluate
         * or kaon2:ifTrue predicate are passed in boundValues.
         *
         * @param context                       the context for the evaluation
         * @param boundValues                   the arguments of the kaon2:evalute or kaon2:ifTrue predicate
         * @return                              the result value
         * @throws KAON2Exception               thrown if there is an error
         */
        public Term evaluate(ExpressionEvaluatorContext context,Term[] boundValues) throws KAON2Exception {
            if (m_arguments.length!=2)
                throw new KAON2Exception("The function 'convert' requires exactly two arguments.");
            // The first argument is the currency.
            Term result=m_arguments[0].evaluate(null, boundValues);
            // If it does not evaluate to the Currency object, throw an error. Don't worry: the exeption
            // below will be caught by the kaon2:evaluate or kaon2:ifTrue predicate.
            if (!(result instanceof Constant))
                throw new KAON2Exception("Type error.");
            Object resultValue=((Constant)result).getValue();
            if (!(resultValue instanceof Currency))
                throw new KAON2Exception("Type error.");
            Currency currency=(Currency)resultValue;
            // The second argument is the new currency code.
            result=m_arguments[1].evaluate(null, boundValues);
            if (!(result instanceof Constant))
                throw new KAON2Exception("Type error.");
            resultValue=((Constant)result).getValue();
            if (!(resultValue instanceof String))
                throw new KAON2Exception("Type error.");
            String newCode=(String)resultValue;

            // We now perform the actual conversion. For simplicity we avoid numerous checks.
            double newAmount=currency.getAmount()*s_currencyToEUR.get(currency.getCode())/s_currencyToEUR.get(newCode);

            // Finally, we create the new object.
            return KAON2Manager.factory().constant(new Currency(newAmount,newCode));
        }
        /**
         * Returns the number of arguments.
         * 
         * @return                              the number of arguments
         */
        public int getNumberOfArguments() {
            return m_arguments.length;
        }
        /**
         * Returns the argument with a given index.
         * 
         * @param index                         the index
         * @return                              the argument with a given index
         */
        public ExpressionEvaluator getArgument(int index) {
            return m_arguments[index];
        }

    }
}

?? 快捷鍵說(shuō)明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號(hào) Ctrl + =
減小字號(hào) Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
国产精品乱码一区二三区小蝌蚪| 国产东北露脸精品视频| 亚洲精品视频免费观看| 中文字幕一区视频| 国产精品白丝在线| 亚洲欧洲日本在线| 亚洲色图色小说| 亚洲欧美另类在线| 有码一区二区三区| 亚洲国产欧美在线| 亚洲成人免费视频| 日本sm残虐另类| 精品亚洲国产成人av制服丝袜 | 免费不卡在线观看| 久草中文综合在线| 国产激情91久久精品导航| 国产成人av电影在线观看| 成人18视频在线播放| 不卡av电影在线播放| 日本高清免费不卡视频| 欧美调教femdomvk| 欧美成人激情免费网| 久久久精品综合| 中文字幕一区二区在线观看| 亚洲欧洲成人av每日更新| 亚洲欧美日韩一区| 亚洲3atv精品一区二区三区| 免费在线看一区| 国产成人亚洲综合a∨婷婷图片 | 国产欧美一区视频| 亚洲欧洲精品一区二区精品久久久| 亚洲精品国产高清久久伦理二区| 日日夜夜精品视频天天综合网| 蜜桃视频免费观看一区| 国产精品一区二区在线播放| www.视频一区| 7777精品伊人久久久大香线蕉经典版下载| 精品久久人人做人人爰| 国产精品灌醉下药二区| 亚洲午夜精品网| 久久草av在线| 91丨国产丨九色丨pron| 欧美日韩国产123区| 久久久久久久久伊人| 亚洲视频一区在线| 久久国产精品色婷婷| 99免费精品视频| 制服丝袜成人动漫| 中文字幕在线一区| 天天综合日日夜夜精品| 国产成人亚洲综合a∨婷婷| 欧美综合天天夜夜久久| 久久麻豆一区二区| 亚洲国产精品人人做人人爽| 国产一区二区三区四| 在线免费观看不卡av| 久久久噜噜噜久久中文字幕色伊伊 | 99精品视频在线免费观看| 欧美日韩精品一区二区在线播放| 欧美精品一区二区三区在线| 亚洲三级理论片| 久久99国产精品尤物| 91成人免费电影| 欧美韩日一区二区三区四区| 五月天视频一区| 成人av在线电影| 精品欧美一区二区三区精品久久 | www.99精品| 日韩欧美资源站| 亚洲一区二区高清| 国产成人av福利| 欧美成人精品3d动漫h| 亚洲国产精品久久人人爱| 成人午夜精品一区二区三区| 日韩三级高清在线| 香蕉成人伊视频在线观看| 99久久婷婷国产综合精品电影| 日韩免费一区二区| 天天影视涩香欲综合网| 中文字幕亚洲精品在线观看| 精品制服美女久久| 91精品欧美久久久久久动漫| 亚洲精品水蜜桃| 99国产精品久久久久久久久久久| 欧美一区二区三区在线观看| 亚洲一区日韩精品中文字幕| 99久久国产综合色|国产精品| 久久综合狠狠综合久久激情| 日韩成人一区二区| 欧美影院午夜播放| 一区二区在线电影| 91丨九色丨尤物| 亚洲欧洲无码一区二区三区| 成人综合婷婷国产精品久久蜜臀 | 一区二区三区中文免费| 97久久精品人人爽人人爽蜜臀 | 精品一区二区在线观看| 欧美一区二区黄| 欧美aⅴ一区二区三区视频| 欧美精品一二三区| 午夜电影网亚洲视频| 欧美三级日韩三级国产三级| 亚洲国产一区二区三区青草影视| 91一区二区在线观看| 亚洲美腿欧美偷拍| 91福利精品视频| 亚洲成av人片在线观看| 欧美日韩你懂得| 日本亚洲最大的色成网站www| 欧美精选在线播放| 日本欧美肥老太交大片| 日韩一区二区中文字幕| 精品亚洲aⅴ乱码一区二区三区| 日韩美女视频一区二区在线观看| 六月丁香综合在线视频| 精品国产凹凸成av人导航| 国内精品国产成人| 久久久91精品国产一区二区精品 | 99久久婷婷国产综合精品电影 | 精彩视频一区二区| 国产欧美一区二区精品婷婷 | 精品第一国产综合精品aⅴ| 韩国理伦片一区二区三区在线播放| 久久综合一区二区| 不卡的av电影在线观看| 亚洲永久精品大片| 日韩视频一区在线观看| 国产精品性做久久久久久| 国产精品理论片在线观看| 在线观看日韩av先锋影音电影院| 亚洲国产精品嫩草影院| 精品裸体舞一区二区三区| 国产成人三级在线观看| 一区二区视频在线看| 欧美一区二区三区不卡| 成人精品免费看| 午夜精品在线看| 久久色成人在线| 91老师国产黑色丝袜在线| 石原莉奈一区二区三区在线观看| 久久亚洲春色中文字幕久久久| 成人激情小说网站| 日韩激情av在线| 国产欧美日韩精品一区| 色婷婷av一区二区三区gif| 日韩av一区二| 亚洲精品一区二区三区蜜桃下载| 99riav一区二区三区| 亚洲自拍偷拍综合| 欧美一级视频精品观看| 国产成人精品影院| 日韩精品五月天| 国产午夜精品久久久久久久| 91同城在线观看| 日韩精品一二三| 日韩毛片视频在线看| 555夜色666亚洲国产免| 国产一区二区三区香蕉| 精品国产网站在线观看| 色呦呦日韩精品| 久久精品国产秦先生| 欧美激情一区二区在线| 国产一区中文字幕| 亚洲一区二区三区四区的| 亚洲精品一区二区三区蜜桃下载 | 成人的网站免费观看| 伊人性伊人情综合网| 国产欧美一区二区精品久导航| 色成人在线视频| 国产在线不卡一区| 一卡二卡三卡日韩欧美| 中文幕一区二区三区久久蜜桃| 欧美色图在线观看| 国产黑丝在线一区二区三区| 亚洲一区二区三区四区在线观看| 欧美激情一区二区在线| 91精品国产色综合久久| aaa亚洲精品| 麻豆91在线播放| 亚洲v日本v欧美v久久精品| 日本一区二区三区在线观看| 欧美精品在线一区二区三区| 久久av老司机精品网站导航| 亚洲国产日产av| 国产精品私房写真福利视频| 欧美精品在线视频| 91久久久免费一区二区| 国产一区二区三区四区五区美女| 亚洲综合丝袜美腿| 国产欧美精品一区二区色综合| 欧美亚洲国产一区在线观看网站| 国产麻豆91精品| 日本成人超碰在线观看| 樱花影视一区二区| 日本一区二区综合亚洲| 日韩精品一区二区三区在线| 欧美亚洲动漫制服丝袜| av高清不卡在线| 99热这里都是精品| 高清不卡在线观看av|