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

📄 testdata.java

📁 Jena推理机
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*
 * (c) Copyright 2005, 2006, 2007 Hewlett-Packard Development Company, LP
 * [See end of file]
 */

package com.hp.hpl.jena.rdf.arp.states.test;

import java.io.FileWriter;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Random;
import java.util.Set;
import java.util.TreeSet;

import org.xml.sax.Attributes;
import org.xml.sax.SAXParseException;

import com.hp.hpl.jena.rdf.arp.ARPErrorNumbers;
import com.hp.hpl.jena.rdf.arp.impl.AbsXMLContext;
import com.hp.hpl.jena.rdf.arp.impl.AttributeLexer;
import com.hp.hpl.jena.rdf.arp.impl.Names;
import com.hp.hpl.jena.rdf.arp.impl.URIReference;
import com.hp.hpl.jena.rdf.arp.impl.XMLBaselessContext;
import com.hp.hpl.jena.rdf.arp.impl.XMLContext;
import com.hp.hpl.jena.rdf.arp.impl.XMLHandler;
import com.hp.hpl.jena.rdf.arp.states.AbsXMLLiteral;
import com.hp.hpl.jena.rdf.arp.states.DAMLCollection;
import com.hp.hpl.jena.rdf.arp.states.FrameI;
import com.hp.hpl.jena.rdf.arp.states.HasSubjectFrameI;
import com.hp.hpl.jena.rdf.arp.states.InnerXMLLiteral;
import com.hp.hpl.jena.rdf.arp.states.LookingForRDF;
import com.hp.hpl.jena.rdf.arp.states.OuterXMLLiteral;
import com.hp.hpl.jena.rdf.arp.states.RDFCollection;
import com.hp.hpl.jena.rdf.arp.states.WantEmpty;
import com.hp.hpl.jena.rdf.arp.states.WantLiteralValueOrDescription;
import com.hp.hpl.jena.rdf.arp.states.WantPropertyElement;
import com.hp.hpl.jena.rdf.arp.states.WantTopLevelDescription;
import com.hp.hpl.jena.rdf.arp.states.WantTypedLiteral;
import com.hp.hpl.jena.rdf.arp.states.WantsObjectFrameI;

/**
 * For each state s, for each element-attribute event e1, - test s, e1 - if s,
 * e1 is not an error + test s, e1; Description; test s,e1, eg:prop; test s, e1,
 * end; for each element-attribute event e2 + test s, e1, e2 if s, e1, e2 is not
 * an error
 * 
 * @author Jeremy J. Carroll
 * 
 */
public class TestData implements ARPErrorNumbers{

    // TODO: not for 2.3. get rid of short names all together, not good idea.
    
    
    private static final URIReference foo = URIReference.createNoChecks("http://foo/");
    private static final URIReference bar = URIReference.createNoChecks("http://bar/");

    static TestHandler xmlHandler = new TestHandler();
//    static {
//        try {
//            xmlHandler.initParse("http://example.org/", "");
//        } catch (SAXParseException e) {
//           e.printStackTrace();
//        }
//        
//    }
    static String dataFile = "testing/arp/state.txt";
    static AbsXMLContext xmlContext;
    
    static { 
        try {
            xmlContext= new XMLBaselessContext(xmlHandler,
                    ERR_RESOLVING_AGAINST_RELATIVE_BASE).withBase(xmlHandler,"http://example.org/base/");
        } catch (SAXParseException e) {
            throw new RuntimeException(e);
        }
    }
    static TestFrame testFrame = new TestFrame(xmlHandler, xmlContext);
    
    static char white[] = { 32, 32, 32, 32, 32 };

    static char black[] = { 97, 98, 99, 100, 101 };

    private static final AttrEvent xmlSpace = new AttrEvent(QName.xml("space"));
    static Event allEvents[] = { 
           new ElementEvent(QName.rdf("li")),
            new ElementEvent(QName.rdf("Description")),
            new ElementEvent("F",QName.rdf("RDF")),
            new ElementEvent(QName.eg("Goo")),
            new AttrEvent(QName.xml("base")),
            new AttrEvent("g", QName.xml("lang"), "en"),
            new AttrEvent(QName.eg("foo")), 
            xmlSpace,
            new AttrEvent("B", QName.rdf("bagID"), "en"),
            new AttrEvent(QName.rdf("about")),
            new AttrEvent("h", QName.rdf("aboutEach"), "en"),
            new AttrEvent("H", QName.rdf("aboutEachPrefix"), "en"),
            new AttrEvent(QName.rdf("ID")), new AttrEvent(QName.rdf("nodeID")),
            new AttrEvent(QName.rdf("resource")),
            new AttrEvent(QName.rdf("type")),
            new AttrEvent(QName.rdf("datatype")),
            new AttrEvent("C", QName.rdf("parseType"), "Collection"),
            new AttrEvent("L", QName.rdf("parseType"), "Literal"),
            new AttrEvent("R", QName.rdf("parseType"), "Resource"),
            new InternalEvent("e", "</end>") {
                FrameI apply(FrameI from, Attributes att) throws SAXParseException {
                    from.endElement();
                    return from.getParent();
                }
            }, new InternalEvent("O", "object") {
                FrameI apply(FrameI from, Attributes att) {
                    ((WantsObjectFrameI) from).theObject(foo);
                    return from;
                }
            }, new InternalEvent("W", "white") {
                FrameI apply(FrameI from, Attributes att) throws SAXParseException {
                    from.characters(white, 0, 5);
                    return from;
                }
            }, new InternalEvent("Q", "'abcde'") {
                FrameI apply(FrameI from, Attributes att) throws SAXParseException {
                    from.characters(black, 0, 5);
                    return from;
                }
            }, 
            new InternalEvent("P", "pred-object") {
                FrameI apply(FrameI from, Attributes att) {
                    ((HasSubjectFrameI) from).aPredAndObj(foo,bar);
                    return from;
                }
            }, };

    static Map short2Event = new HashMap();
    static {
        for (int i=0;i<allEvents.length;i++) {
            String key = allEvents[i].oneChar;
            if (short2Event.get(key)!=null)
                System.err.println("Duplicate event code: "+key);
            short2Event.put(key,allEvents[i]);
        }
    }
    static Map state2Name = new HashMap();

    static Map state2ShortName = new HashMap();

    static Map shortName2State = new HashMap();

    static Map state2Args = new HashMap();

    static void add(String sh, String nm, Class f, Object args[]) {
        state2Name.put(f, nm);
        sh = getSimpleName(f);
        if (shortName2State.get(sh) != null) {
            System.err.println("Duplicate: " + sh);
        }
        state2Args.put(f, args);
        shortName2State.put(sh, f);
        state2ShortName.put(f, sh);
    }

    private static String getSimpleName(Class f) {
        return XMLHandler.getSimpleName(f);
    }

    static AttributeLexer ap = new AttributeLexer(testFrame, 0, 0);
    static {
        add("ix", "inner-xml-literal", InnerXMLLiteral.class,
                new Object[] { testFrame, "foo", testFrame.namespaces });
        add("xl", "xml-literal", OuterXMLLiteral.class, new Object[] {
                testFrame, xmlContext });
        add("ip", "vanilla-prop-elt", WantLiteralValueOrDescription.class,
                new Object[] { testFrame, xmlContext });
        add("tl", "typed-literal", WantTypedLiteral.class, new Object[] {
                testFrame, "http://ex/dt", xmlContext });
        add("dl", "daml:collection", DAMLCollection.class, new Object[] {
                testFrame, xmlContext });
        add("cl", "collection", RDFCollection.class, new Object[] {
                testFrame, xmlContext });
        add("tp", "top-level", WantTopLevelDescription.class,
                new Object[] { testFrame, ap });
        add("em", "empty-prop-elt", WantEmpty.class, new Object[] {
                testFrame, xmlContext });
        add("de", "inside-Description", WantPropertyElement.class,
                new Object[] { testFrame, xmlContext });
        add("RD", "looking-for-RDF", LookingForRDF.class, new Object[] {
                testFrame, ap });
    }


    int localCount;

    int globalCount;

    private EventList eventList = new EventList();

    public TestData() {
        super();
    }
//    String characters[] = {
//            "G",
//            "G e",
//            "G e G",
//            "Q",
//            "Q G",
//            "Q e",
//            "e",
//            "P",
//            "O",
//        };
    String characters[] = {
        "<eg:Goo>",
        "<eg:Goo> </end>",
        "<eg:Goo> </end> <eg:Goo>",
        "'abcde'",
        "'abcde' <eg:Goo>",
        "'abcde' </end>",
        "</end>",
        "pred-object",
        "object",
    };

    boolean inCharacterize = false;
    void characterize(Class f){
        inCharacterize = true;
        int sz = eventList.size;
        StringBuffer rslt = new StringBuffer();

⌨️ 快捷键说明

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