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

📄 jracer.java

📁 Semantic Web Ontology Editor
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*
 * Created on Aug 24, 2005
 */
package org.mindswap.swoop.racer;

import java.io.File;
import java.io.FilenameFilter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTree;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;

import org.mindswap.pellet.output.TableData;
import org.mindswap.pellet.utils.AlphaNumericComparator;
import org.mindswap.pellet.utils.FileUtils;
import org.mindswap.pellet.utils.Timer;
import org.mindswap.pellet.utils.Timers;

/**
 * @author Evren Sirin
 *
 */
public class JRacer {
   public RacerClient racer = new RacerClient("localhost", 8088);
   Timers timers = new Timers();
   Timer t = null;

   Set conceptSet;
   String[] concepts;

   public JRacer() throws Exception {
       racer.openConnection();
//       racer.send("(set-nrql-mode 1)");
//       racer.send("(enable-optimized-query-processing t)");
//       racer.send("(enable-nrql-warnings)");

       reset();
   }

   void runDLBenchmark() throws IOException, RacerException {
       String dirName = "/mindswap/pellet/test_data/dl-benchmark/tbox/";
               File dir = new File(dirName);
               String[] files = dir.list( new FilenameFilter() {
                       public boolean accept(File dir, String name) {
                               return dir != null && name.endsWith(".tkb")
                       && name.indexOf("-roles")==-1
                       && name.indexOf("-cd")==-1
                       && name.indexOf("pdwq")==-1
                       && name.indexOf("people")==-1
                       && name.indexOf("veda-all")==-1;
                       }
               });
               Arrays.sort(files, AlphaNumericComparator.CASE_INSENSITIVE);

               TableData table = new TableData(Arrays.asList(new String[] { "Name", " Time"} ));
               for(int i = 0; i < files.length; i++) {
                       System.out.print((i+1) + ") ");
                       List data = new ArrayList();
                       data.add( files[i] );
               read( dirName + files[i] );

               classify();

               data.add(timers.getTimer("classify").getTotal()+"");
               table.addRow(data);
               reset();
               }
               System.out.println( table );
   }

   void runLUBM(int limit) throws Exception {
       String[] data;

       racer.send("(full-reset)");
       racer.send("(set-nrql-mode 1)");
//        racer.send("(set-unique-name-assumption t)");
       racer.send("(enable-optimized-query-processing)");

       String dirName = "/mindswap/pellet/files/LUBM/";
               File dir = new File(dirName);
               String[] files = dir.list(new FilenameFilter() {
                       public boolean accept(File dir, String name) {
                               return (dir != null) && name.endsWith(".owl");
                       }
               });
               Arrays.sort(files, AlphaNumericComparator.CASE_INSENSITIVE);

       t = timers.startTimer( "reading" );
               for(int i = 0; i < limit; i++) {
                       System.out.print((i+1) + ") ");
                       String file = files[i];
                       int index = files[i].indexOf('.');
                       String name = files[i].substring(0, index);

               System.out.println( "Reading " + name );
//              racer.RACERreadFile( dirName + file );
               racer.readOWL( "file:" + dirName + file );
               }
       t.stop();
       System.out.println( "Reading: " + t.getTotal() + "");
//        printTree( "TOP", "" );

       TableData table = new TableData( Arrays.asList( new String[] { "No", "Answers", "Time" } ) );

               consistency();
               table.addRow( Arrays.asList( new String[] {"Consistency", "1", ""+t.getTotal()} ) );

               classify();

       files = dir.list(new FilenameFilter() {
                       public boolean accept(File dir, String name) {
                               return (dir != null) && name.startsWith("Query") && name.endsWith(".txt");
                       }
               });
               Arrays.sort(files, AlphaNumericComparator.CASE_INSENSITIVE);

               for(int i = 0; i < files.length; i++) {
//                  if( i != 0 ) continue;
                       System.out.print((i+1) + ") ");
                       String file = files[i];
                       int index = files[i].indexOf('.');
                       String name = files[i].substring(0, index);

               System.out.println( name );
               String query = FileUtils.readFile( dirName + file );
//              System.out.println( query );

               List row = new ArrayList();
               row.add("Q" + (i+1));

//              t = timers.startTimer( "Q" + (i+1) );
//              int count = racer.nRQL( query, false );
//              t.stop();

               query = query.substring( query.indexOf( "(", 1 ), query.length()-1 );
               int b = 0;
               int e = findMatchingP( query ) + 1;
               String vars = query.substring( b, e );
               String body = query.substring( e + 1 );
               t = timers.startTimer( "Q" + (i+1) );
               racer.send("(racer-prepare-query " + vars + "  " + body + " :id q" + i + ")");
               String c = racer.send("(get-answer-size q" + i + " t)");
               t.stop();
               int count = c.equalsIgnoreCase( "NIL" ) ? 0 : Integer.parseInt(c);

               System.out.println( "Answers "  + count);
               System.out.println( "Time "  + t.getTotal());
//              System.out.println( result );
               row.add( "" + count );
               row.add( "" +  t.getTotal() );
               table.addRow( row );
               }

               System.out.println( table );

//        String[] data = null;
//
//        String ns = null;
////        ns = "http://www.lehigh.edu/~zhp2/2004/0401/univ-bench.owl#";
//        ns = "http://www.lehigh.edu/~zhp2/univ-bench.daml#";
//
//        t = timers.startTimer( "q1" );
//        data = racer.conceptInstances( "|" + ns + "Student|" );
//        t.stop();
//
//        System.out.println( "Students " + data.length + " (" + t.getTotal() + ")"  );
//
//        t = timers.startTimer( "q0" );
//        data = racer.conceptInstances( "|" + ns + "Department|" );
//        t.stop();
//
//        System.out.println( "Departments " + data.length + " (" + t.getTotal() + ")"  );
//
//        t = timers.startTimer( "q2" );
//        data = racer.conceptInstances( "|" + ns + "Chair|" );
//        t.stop();
//
//        System.out.println( "Chair " + data.length + " (" + t.getTotal() + ")"  );
//
//        t = timers.startTimer( "q3" );
//        data = racer.conceptInstances( "|" + ns + "AssociateProfessor|" );
//        t.stop();
//
//        System.out.println( "AssociateProfessor " + data.length + " (" + t.getTotal() + ")"  );
   }

   void run() throws Exception {
       Timer t;

       String dir = "/mindswap/pellet/test_data/dl-benchmark/";
       String tbox = dir + "tbox/";
       String abox = dir + "abox/";
       String file;

       file = tbox + "galen.tkb";
       file = abox + "bike81.akb";

//        file = "http://www.cs.man.ac.uk/~horrocks/OWL/Ontologies/galen.owl";
//        file = "file://C/mindswap/pellet/files/galen.owl";
//        file = "http://protege.stanford.edu/plugins/owl/owl-library/not-galen.owl";
//        file = "file://C/mindswap/pellet/files/nasa-easier.owl";
//        file = "http://www.w3.org/2001/sw/WebOnt/guide-src/wine.owl";
//        file = "http://www.mindswap.org/ontologies/dice.owl";
//        file = "http://www.aktors.org/ontology/portal";
       file = "file:/tools/kaon2/ontologies/dolce/dolce.owl";
//        file = "file:/FEARMO.owl";
       file = "file:/mindswap/ontologies/dice.owl";

       System.out.print( "Reading " + file + "..." );
       t = timers.startTimer( "reading" );

       if( file.startsWith( "http:" ) || file.startsWith( "file:" ) )
           racer.readOWL( file );
       else
           racer.RACERreadFile( file );
       t.stop();
       System.out.println( "done. (" + t.getTotal() + ")");

       info();

//        consistency();

       classify();

       realize();

//        System.out.println(racer.individualInstanceP("I3", "C51"));

//       createTree();

       printTree( "TOP", "" );

//        printTBox();
//
//        printABox();

//        RacerVerify.verify( file, racer );

//        RacerVerify.verify( "C:\\mindswap\\pellet\\files\\galen-local.owl", racer );

       racer.closeConnection();
   }

   void read( String file ) throws IOException, RacerException {
       String name = file;
               int index = name.indexOf('.');

⌨️ 快捷键说明

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