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

📄 regression.java

📁 Jena推理机
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
                    stmts[i*num+j] = stmt;
                }
            }

            int numStmts = num*num;
            boolean stmtf[] = new boolean[numStmts];
            boolean subjf[] = new boolean[num];
            boolean predf[] = new boolean[num];

            n = 100;
            n++; if (m.size() != numStmts) error(test, n);
            for (int i=0; i<numStmts; i++) {
                stmtf[i] = false;
            }
            for (int i=0; i<num; i++) {
                subjf[i] = false;
                predf[i] = false;
            }

            boolean found = false;
            ResIterator rIter = m.listSubjects();
            while (rIter.hasNext()) {
                Resource subj = rIter.nextResource();
                found = false;
                for (int i=0; i<num; i++) {
                    if (subj.equals(subject[i])) {
                        found = true;
                        if (subjf[i]) error(test, 110);
                        subjf[i] = true;
                    }
                }
                if (! found) error(test, 120);
            }
            for (int i=0; i<num; i++) {
                if (! subjf[i]) error(test, 120+i);
            }

//            System.err.println( "WARNING: listNameSpace testing wonky for the moment" );
//            NsIterator nIter = m.listNameSpaces();
//            HashSet fromIterator = new HashSet();
//            HashSet fromPredicates = new HashSet();
//            while (nIter.hasNext()) fromIterator.add( nIter.next() );
//            for (int i = 0; i < num; i += 1) fromPredicates.add( predicate[i].getNameSpace() );
//            if (fromIterator.equals( fromPredicates ))
//                {}
//            else
//                {
//                System.err.println( "| oh dear." );
//                System.err.println( "|  predicate namespaces: " + fromPredicates );
//                System.err.println( "|  iterator namespaces: " + fromIterator );
//                }

            NsIterator nIter = m.listNameSpaces();
            while (nIter.hasNext()) {
                String ns = nIter.nextNs();
                found = false;
                for (int i=0; i<num; i++) {
                    if (ns.equals(predicate[i].getNameSpace())) {
                        found = true;
                        if (predf[i]) error(test, 130);
                        predf[i] = true;
                    }
                }
                if (! found) error(test, 140);
            }
            for (int i=0; i<num; i++) {
                if (! predf[i]) error(test, 140+i);
            }

            StmtIterator sIter = m.listStatements();
            while (sIter.hasNext()) {
                Statement stmt = sIter.nextStatement();
                found = false;
                for (int i=0; i<numStmts; i++) {
                    if (stmt.equals(stmts[i])) {
                        found = true;
                        if (stmtf[i]) error(test, 150);
                        stmtf[i] = true;
                    }
                }
                if (! found) error(test, 160);
            }
            for (int i=0; i<numStmts; i++) {
                if (! stmtf[i]) error(test, 160+i);
            }

// SEE the tests in model.test: TestReifiedStatements and TestStatementResources
//            {
//            System.err.println( "WARNING: reification testing suppressed for the moment" );
///* Reification is not working properly
//
//                for (int i=0; i<num; i++) {
//                    stmtf[i] = false;
//                    m.add(stmts[i], predicate[i], i);
//                }
//                sIter = m.listReifiedStatements();
//                while (sIter.hasNext()) {
//                    Statement stmt = sIter.next();
//                    found = false;
//                    for (int i=0; i<num; i++) {
//                        if (stmt.equals(stmts[i])) {
//                            found = true;
//                            if (stmtf[i]) error(test, 200);
//                            stmtf[i] = true;
//                        }
//                    }
//                    if (! found) error(test, 210);
//                }
//                for (int i=0; i<num; i++) {
//                    if (! stmtf[i]) error(test, 220+i);
//                } */
//            }

            {
                NodeIterator iter;
                boolean[] object= new boolean[num*num];
                n = 300;
                for (int i=0; i<(num*num); i++) {
                    object[i] = false;
                }
                iter = m.listObjectsOfProperty(predicate[0]);
                while (iter.hasNext()) {
                    Literal l = (Literal) iter.nextNode();
                    int i = l.getInt();
                    object[i] = true;
                }
                for (int i=0; i<(num*num); i++) {
                    if ((i % num) == 0) {
                      if (! object[i]) error(test,300+i);
                    } else {
                      if (  object[i]) error(test,350+i);
                    }
                }
            }

            {
                NodeIterator iter;
                boolean[] object = new boolean[num];
                n=400;
                Resource subj = m.createResource();
                for (int i=0; i<num; i++) {
                    m.add(subj, RDF.value, i);
                    object[i] = false;
                }

                iter = m.listObjectsOfProperty(subj, RDF.value);
                while (iter.hasNext()) {
                    int i = ((Literal)iter.nextNode()).getInt();
                    object[i] = true;
                }
                for (int i=0; i<(num); i++) {
                    if (! object[i]) error(test,n+i);
                }
            }

            {
                int count = 0;
                NodeIterator iter;
                n = 500;
                iter = m.listObjects();
                while (iter.hasNext()) {
                    iter.nextNode();
                    count++;
                }
                if (! (count == 25)) 
                    {
                    error(test, n+count);
                    }
            }
        } catch (Exception e) {
            logger.error( "test " + test + "[" + n + "]", e );
            errors = true;
        }
//        System.out.println("End of " + test);
    }

    /** test add and remove sets and models
     * @param m the model implementation under test
     */
    public void test7(Model m1, Model m2) {
        String  test = "Test7";
        int     n = 0;

        try {
            StmtIterator iter;
//            System.out.println("Beginning " + test);

            try {
                n=100;
                n++; iter = m1.listStatements();
                n++; m2.add(iter); iter.close();
                n++; if (! (m1.size() == m2.size())) error(test,n);
                n++; iter = m1.listStatements();
                n=110;
                while (iter.hasNext()) {
                    n++;    if (! m2.contains(iter.nextStatement())) error(test, n);
                }
                n=200;
                iter = m2.listStatements();
                while (iter.hasNext()) {
                    n++;    if (! m1.contains(iter.nextStatement())) error(test,n);
                }
            } catch (Exception e) {
                error(test, n, e);
            }

            try {
                n=300;
                m1.add(m1.createResource(),
                       RDF.value,
                       m1.createResource());
                m1.add(m1.createResource(),
                       RDF.value,
                       m1.createResource());
                m1.add(m1.createResource(),
                       RDF.value,
                       m1.createResource());
                n++; iter = m1.listStatements();
                n++; m2.remove(iter.nextStatement());
                n++; m2.remove(iter); iter.close();
                n++; if (! (m2.size() == 0)) error(test,n);
            } catch (Exception e) {
                error(test, n, e);
            }

            try {
                n=400;
                n++; m2.add(m1);
                n++; if (! (m1.size() == m2.size())) error(test,n);
                n++; iter = m1.listStatements();
                n=410;
                while (iter.hasNext()) {
                    n++;    if (! m2.contains(iter.nextStatement())) error(test, n);
                }
                n=500;
                iter = m2.listStatements();
                while (iter.hasNext()) {
                    n++;    if (! m1.contains(iter.nextStatement())) error(test,n);
                }
            } catch (Exception e) {
                error(test, n, e);
            }

            try {
                n=600;
                // System.err.println( "| m2.size() = " + m2.size() );
                n++; m2.remove(m1);
                n++; if (! (m2.size() == 0)) error(test,n);
                // System.err.println( "| after: m2.size = " + m2.size() );
            } catch (Exception e) {
                error(test, n, e);
            }
        } catch (Exception e) {
            logger.error( "test " + test + "[" + n + "]", e );
            errors = true;
        }
//        System.out.println("End of " + test);
    }

    /** test list subjects with methods
     * @param m the model implementation under test
     */
    public void test8(Model m) {
        String  test = "Test8";
        int     n = 0;
        int     num = 5;

        Resource  subject[] = new Resource[num];
        Property  predicate[] = new Property[num];
        Vector    stmtv = new Vector();
        Statement stmts[];
        Statement stmt;

        String suri = "http://aldabaran/test8/s";
        String puri = "http://aldabaran/test8/";

        boolean    tvBoolean[] = { false, true };
        long       tvLong[]    = { 123, 321 };
        char       tvChar[]    = { '@', ';' };
        float      tvFloat[]     = { 456.789f, 789.456f };
        double     tvDouble[]  = { 123.456, 456.123 };
        String     tvString[]  = { "test8 testing string 1",
                                   "test8 testing string 2" };
        String     lang[]      = { "en", "fr" };

        boolean subjf[] = new boolean[num];
        boolean predf[] = new boolean[num];

        int numObj = 9;
        boolean objf[] = new boolean[numObj];
        RDFNode object[] = new RDFNode[numObj];


        // System.out.println("Beginning " + test);

        try {
            Literal     tvLitObj[]  = { m.createLiteral(new LitTestObjF()),
                                        m.createLiteral(new LitTestObjF()) };
            Resource    tvResObj[]  = { m.createResource(new ResTestObjF()),
                                        m.createResource(new ResTestObjF()) };

            for (int i = 0; i<num; i++) {
                subject[i] = m.createResource(suri + Integer.toString(i));
                predicate[i] = m.createProperty(puri + Integer.toString(i),
                "p");
            }

            for (int i=0; i<num; i++) {
                m.add(subject[i], predicate[4], false);
            }

            for (int i=0; i<2; i++) {
                for (int j=0; j<2; j++) {
                    stmt = m.createStatement(subject[i], predicate[j],
                                            tvBoolean[j]);
                    m.add(stmt);
                    stmt = m.createStatement(subject[i], predicate[j],
                                             tvLong[j]);
                    m.add(stmt);
                    stmt = m.createStatement(subject[i], predicate[j],
                                             tvChar[j]);
                    m.add(stmt);
                    stmt = m.createStatement(subject[i], predicate[j],
                                             tvFloat[j]);
                    m.add(stmt);
                    stmt = m.createStatement(subject[i], predicate[j],
                                             tvDouble[j]);
                    m.add(stmt);
                    stmt = m.createStatement(subject[i], predicate[j],
                                            tvString[j]);
                    m.add(stmt);
                    stmt = m.createStatement(subject[i], predicate[j],
                                            tvString[j], lang[j]);
                    m.add(stmt);
                    stmt = m.createStatement(subject[i], predicate[j],
                                            tvLitObj[j]);
                    m.add(stmt);
                    stmt = m.createStatement(subject[i], predicate[j],
                                            tvResObj[j]);
                    m.add(stmt);
                }
            }
            object[0] = m.createLiteral(tvBoolean[1]);
            object[1] = m.createLiteral(tvLong[1]);
            object[2] = m.createLiteral(tvChar[1]);
            object[3] = m.createLiteral(tvFloat[1]);
            object[4] = m.createLiteral(tvDouble[1]);
            object[5] = m.createLiteral(tvString[1]);
            object[6] = m.createLiteral(tvString[1], lang[1]);
            object[7] = tvLitObj[1];
            object[8] = tvResObj[1];

⌨️ 快捷键说明

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