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

📄 testbugreports.java

📁 Jena推理机
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
    /**
     * Bug report by Thorsten Liebig [liebig@informatik.uni-ulm.de] -
     * SymmetricProperty etc not visible in list ont properties
     */
    public void test_tl_01() {
        String sourceT =
            "<rdf:RDF "
                + "    xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#'"
                + "    xmlns:rdfs='http://www.w3.org/2000/01/rdf-schema#'"
                + "    xmlns:owl=\"http://www.w3.org/2002/07/owl#\">"
                + "   <owl:SymmetricProperty rdf:about='http://example.org/foo#p1'>"
                + "   </owl:SymmetricProperty>"
                + "   <owl:TransitiveProperty rdf:about='http://example.org/foo#p2'>"
                + "   </owl:TransitiveProperty>"
                + "   <owl:InverseFunctionalProperty rdf:about='http://example.org/foo#p3'>"
                + "   </owl:InverseFunctionalProperty>"
                + "</rdf:RDF>";

        OntModel m = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM_RULE_INF, null);
        m.read(new ByteArrayInputStream(sourceT.getBytes()), "http://example.org/foo");

        boolean foundP1 = false;
        boolean foundP2 = false;
        boolean foundP3 = false;

        // iterator of properties should include p1-3
        for (Iterator i = m.listOntProperties(); i.hasNext();) {
            Resource r = (Resource) i.next();
            foundP1 = foundP1 || r.getURI().equals("http://example.org/foo#p1");
            foundP2 = foundP2 || r.getURI().equals("http://example.org/foo#p2");
            foundP3 = foundP3 || r.getURI().equals("http://example.org/foo#p3");
        }

        assertTrue("p1 not listed", foundP1);
        assertTrue("p2 not listed", foundP2);
        assertTrue("p3 not listed", foundP3);

        foundP1 = false;
        foundP2 = false;
        foundP3 = false;

        // iterator of object properties should include p1-3
        for (Iterator i = m.listObjectProperties(); i.hasNext();) {
            Resource r = (Resource) i.next();
            foundP1 = foundP1 || r.getURI().equals("http://example.org/foo#p1");
            foundP2 = foundP2 || r.getURI().equals("http://example.org/foo#p2");
            foundP3 = foundP3 || r.getURI().equals("http://example.org/foo#p3");
        }

        assertTrue("p1 not listed", foundP1);
        assertTrue("p2 not listed", foundP2);
        assertTrue("p3 not listed", foundP3);
    }

    /** Bug report by Dave Reynolds - SF bug report 810492 */
    public void test_der_01() {
        OntModel m = ModelFactory.createOntologyModel(OntModelSpec.RDFS_MEM_TRANS_INF, null);
        Resource a = m.createResource("http://example.org#A");
        Resource b = m.createResource("http://example.org#B");
        OntClass A = new OntClassImpl(a.asNode(), (EnhGraph) m) {
            protected boolean hasSuperClassDirect(Resource cls) {
                throw new RuntimeException("did not find direct reasoner");
            }
        };

        // will throw an exception if the wrong code path is taken
        A.hasSuperClass(b, true);
    }

    /**
     * Bug report by Ivan Ferrari (ivan_ferrari_75 [ivan_ferrari_75@yahoo.it]) -
     * duplicate nodes in output
     */
    public void test_if_01() {
        //create a new default model
        OntModel m = ModelFactory.createOntologyModel();

        m.getDocumentManager().addAltEntry(
            "http://www.w3.org/2001/sw/WebOnt/guide-src/wine",
            "file:testing/ontology/bugs/oldwine.owl");
        m.getDocumentManager().addAltEntry(
            "http://www.w3.org/2001/sw/WebOnt/guide-src/food",
            "file:testing/ontology/bugs/oldfood.owl");

        // note: due to bug in the Wine example, we have to manually read the
        // imported food document
        m.getDocumentManager().setProcessImports(false);
        m.read("http://www.w3.org/2001/sw/WebOnt/guide-src/wine");
        m.getDocumentManager().setProcessImports(true);
        m.getDocumentManager().loadImport(m, "http://www.w3.org/2001/sw/WebOnt/guide-src/food");

        OntClass ontclass = m.getOntClass("http://www.w3.org/2001/sw/WebOnt/guide-src/wine#Wine");

        int nNamed = 0;
        int nRestriction = 0;
        int nAnon = 0;

        for (ExtendedIterator iter2 = ontclass.listSuperClasses(true); iter2.hasNext();) {
            OntClass ontsuperclass = (OntClass) iter2.next();

            //this is to view different anonymous IDs
            if (!ontsuperclass.isAnon()) {
                nNamed++;
            }
            else if (ontsuperclass.canAs(Restriction.class)) {
                ontsuperclass.asRestriction();
                nRestriction++;
            }
            else {
                //System.out.println("anon. super: " + ontsuperclass.getId());
                nAnon++;
            }
        }

        assertEquals("Should be two named super classes ", 2, nNamed);
        assertEquals("Should be nine named super classes ", 9, nRestriction);
        assertEquals("Should be no named super classes ", 0, nAnon);
    }

    /** Bug report by Lawrence Tay - missing datatype property */
    public void test_lt_01() {
        OntModel m = ModelFactory.createOntologyModel();

        DatatypeProperty p = m.createDatatypeProperty(NS + "p");
        OntClass c = m.createClass(NS + "A");

        Individual i = m.createIndividual(NS + "i", c);
        i.addProperty(p, "testData");

        int count = 0;

        for (Iterator j = i.listPropertyValues(p); j.hasNext();) {
            //System.err.println("Individual i has p value: " + j.next());
            j.next();
            count++;
        }

        assertEquals("i should have one property", 1, count);
    }


    /** Bug report by David Kensche [david.kensche@post.rwth-aachen.de] - NPE in listDeclaredProperties */
    public void test_dk_01() {
        OntModel m = ModelFactory.createOntologyModel();
        m.read( "file:testing/ontology/bugs/test_dk_01.xml" );

        String NS = "http://localhost:8080/Repository/QueryAgent/UserOntology/qgen-example-1#";
        String[] classes = new String[] {NS+"C1", NS+"C3", NS+"C2"};

        for (int i = 0; i < classes.length; i++) {
            OntClass c = m.getOntClass( classes[i] );
            for (Iterator j = c.listDeclaredProperties(); j.hasNext(); j.next() );
        }
    }

    /** Bug report by Paulo Pinheiro da Silva [pp@ksl.stanford.edu] - exception while accessing PropertyAccessor.getDAMLValue */
    public void test_ppds_01() {
        DAMLModel m = ModelFactory.createDAMLModel();
        DAMLClass c = m.createDAMLClass( NS + "C" );
        DAMLInstance x = m.createDAMLInstance( c, NS + "x" );
        DAMLProperty p = m.createDAMLProperty( NS + "p" );

        x.addProperty( p, "(s (s 0))" );

        PropertyAccessor a = x.accessProperty( p );
        assertNull( "Property accessor value should be null", a.getDAMLValue() );
    }

    /** Bug report by anon at SourceForge - Bug ID 887409 */
    public void test_anon_0() {
        String NS = "http://example.org/foo#";
        String sourceT =
            "<rdf:RDF "
            + "    xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#'"
            + "    xmlns:rdfs='http://www.w3.org/2000/01/rdf-schema#'"
            + "    xmlns:ex='http://example.org/foo#'"
            + "    xmlns:owl='http://www.w3.org/2002/07/owl#'>"
            + "   <owl:ObjectProperty rdf:about='http://example.org/foo#p' />"
            + "   <owl:Class rdf:about='http://example.org/foo#A' />"
            + "   <ex:A rdf:about='http://example.org/foo#x' />"
            + "   <owl:Class rdf:about='http://example.org/foo#B'>"
            + "     <owl:equivalentClass>"
            + "      <owl:Restriction>"
            + "        <owl:onProperty rdf:resource='http://example.org/foo#p' />"
            + "        <owl:hasValue rdf:resource='http://example.org/foo#x' />"
            + "      </owl:Restriction>"
            + "     </owl:equivalentClass>"
            + "   </owl:Class>"
            + "</rdf:RDF>";

        OntModel m = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM, null);
        m.read(new ByteArrayInputStream(sourceT.getBytes()), "http://example.org/foo");

        OntClass B = m.getOntClass( NS + "B");
        Restriction r = B.getEquivalentClass().asRestriction();
        HasValueRestriction hvr = r.asHasValueRestriction();
        RDFNode n = hvr.getHasValue();

        assertTrue( "Should be an individual", n instanceof Individual );
    }

    /** Bug report by Zhao Jun [jeff@seu.edu.cn] - throws no such element exception */
    public void test_zj_0() {
        String NS = "file:/C:/orel/orel0_5.owl#";
        String sourceT =
            "<rdf:RDF " +
            "    xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#'" +
            "    xmlns:rdfs='http://www.w3.org/2000/01/rdf-schema#'" +
            "    xmlns:ex='http://example.org/foo#'" +
            "    xmlns:owl='http://www.w3.org/2002/07/owl#'" +
            "      xmlns:orel='file:/C:/orel/orel0_5.owl#'" +
            "      xml:base='file:/C:/orel/orel0_5.owl#'" +
            "      xmlns='file:/C:/orel/orel0_5.owl#'>" +
            " <owl:ObjectProperty rdf:ID='hasAgent' />" +
            " <owl:ObjectProperty rdf:ID='hasResource' />" +
            " <owl:Class rdf:ID='MyPlay'>" +
            "    <rdfs:subClassOf>" +
            "      <owl:Restriction>" +
            "        <owl:onProperty rdf:resource='file:/C:/orel/orel0_5.owl#hasResource'/>" +
            "        <owl:hasValue>" +
            "          <orel:Resource rdf:ID='myResource'>" +
            "            <orel:resourceURI>http://mp3.com/newcd/sample.mp3</orel:resourceURI>" +
            "          </orel:Resource>" +
            "        </owl:hasValue>" +
            "      </owl:Restriction>" +
            "    </rdfs:subClassOf>" +
            "    <rdfs:subClassOf rdf:resource='http://www.w3.org/2002/07/owl#Thing'/>" +
            "    <rdfs:subClassOf>" +
            "      <owl:Restriction>" +
            "        <owl:onProperty rdf:resource='file:/C:/orel/orel0_5.owl#hasAgent'/>" +
            "        <owl:hasValue>" +
            "          <orel:Agent rdf:ID='myAgent'>" +
            "            <orel:agentPK>123456789</orel:agentPK>" +
            "          </orel:Agent>" +
            "        </owl:hasValue>" +
            "      </owl:Restriction>" +
            "    </rdfs:subClassOf>" +
            "    <rdfs:subClassOf rdf:resource='file:/C:/orel/orel0_5.owl#Play'/>" +
            "  </owl:Class>" +
            "</rdf:RDF>";

        OntModel m = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM_RULE_INF, null);
        m.read(new ByteArrayInputStream(sourceT.getBytes()), "file:/C:/orel/orel0_5.owl");

        OntClass myPlay = m.getOntClass( NS + "MyPlay");
        for (Iterator i = myPlay.listDeclaredProperties(); i.hasNext(); ) {
            //System.err.println( "prop " + i.next() );
            i.next();
        }
    }

    /* Bug reprort by E. Johnson ejohnson@carolina.rr.com - ill formed list in writer */
    public void test_ej_01() {
        String BASE  = "http://jena.hpl.hp.com/testing/ontology";
        String NS = BASE + "#";

        DAMLModel m = ModelFactory.createDAMLModel();
        DAMLClass A = m.createDAMLClass(NS + "A");
        DAMLClass B = m.createDAMLClass(NS + "B");
        DAMLClass C = m.createDAMLClass(NS + "C");
        DAMLList l = m.createDAMLList(new RDFNode[] {A, B, C});

        assertTrue( l.isValid() );

        Model baseModel = m.getBaseModel();
        RDFWriter writer = baseModel.getWriter("RDF/XML-ABBREV");

        // will generate warnings, so suppress until Jeremy has fixed
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        writer.write(baseModel, out, BASE );
    }

    /** Bug report by Harry Chen - closed exception when reading many models */
    public void test_hc_01()
        throws Exception
    {
        for (int i = 0; i < 5; i++) {

            OntModel m = ModelFactory.createOntologyModel();

            FileInputStream ifs = new FileInputStream("testing/ontology/relativenames.rdf");

            //System.out.println("Start reading...");
            m.read(ifs, "http://example.org/foo");
            //System.out.println("Done reading...");

            ifs.close();
            //System.out.println("Closed ifs");
            m.close();
            //System.out.println("Closed model");
        }
    }

    /** Bug report by sinclair bain (slbain) SF bugID 912202 - NPE in createOntResource() when 2nd param is null */
    public void test_sb_01() {
        OntModel model= ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM_RDFS_INF, null);

        Resource result= null;
        Resource nullValueForResourceType= null;

        result= model.createOntResource( OntResource.class, nullValueForResourceType, "http://www.somewhere.com/models#SomeResourceName" );
        assertNotNull( result );
    }

    /* Bug report from Dave Reynolds: listDeclaredProperties not complete */

⌨️ 快捷键说明

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