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

📄 testresource.java

📁 jena2.5.4推理机系统的一种最基本实现 HP实验室出品
💻 JAVA
📖 第 1 页 / 共 3 页
字号:

                    a.setLabel( "new info", null );
                    assertEquals( "Cardinality should be 1", 1, a.getCardinality( prof.LABEL() ) );
                    assertEquals( "a has wrong label", "new info", a.getLabel( null ) );

                    a.removeLabel( "foo", null );
                    assertEquals( "Cardinality should be 1", 1, a.getCardinality( prof.LABEL() ) );
                    a.removeLabel( "new info", null );
                    assertEquals( "Cardinality should be 0", 0, a.getCardinality( prof.LABEL() ) );
                }
            },
            new OntTestCase( "OntResource.label.lang", true, true, true, true ) {
                public void ontTest( OntModel m ) throws Exception {
                    OntResource a = (OntResource) m.getResource( NS + "a" ).as( OntResource.class );

                    a.addLabel( "good", "EN" );
                    assertEquals( "wrong label", "good", a.getLabel( null ) );

                    a.addLabel( "bon", "FR" );

                    assertEquals( "wrong label", "good", a.getLabel( "EN" ) );
                    assertEquals( "wrong label", null, a.getLabel( "EN-GB" ) );  // no literal with a specific enough language
                    assertEquals( "wrong label", "bon", a.getLabel( "FR" ) );

                    assertTrue( "a should have label good", a.hasLabel( "good", "EN" ) );
                    assertTrue( "a should have label bon", a.hasLabel( "bon", "FR" ) );
                    assertTrue( "a should note have label good (DE)", !a.hasLabel( "good", "DE" ) );

                    a.addLabel( "spiffing", "EN-GB" );
                    a.addLabel( "duude", "EN-US" );

                    assertEquals( "wrong label", "spiffing", a.getLabel( "EN-GB" ) );
                    assertEquals( "wrong label", "duude", a.getLabel( "EN-US" ) );
                    assertEquals( "wrong label", null, a.getLabel( "DE" ) );

                    a.addLabel( "abcdef", "AB-CD" );
                    assertEquals( "wrong label", "abcdef", a.getLabel( "AB" ) );
                    assertEquals( "wrong label", null, a.getLabel( "AB-XY" ) );

                    a.removeLabel( "abcde", "AB-CD" );
                    assertEquals( "Cardinality should be 5", 5, a.getCardinality( a.getProfile().LABEL() ) );
                    a.removeLabel( "abcdef", "AB-CD" );
                    assertEquals( "Cardinality should be 4", 4, a.getCardinality( a.getProfile().LABEL() ) );
                }
            },
            new OntTestCase( "OntResource.comment.nolang", true, true, true, true ) {
                public void ontTest( OntModel m ) throws Exception {
                    Profile prof = m.getProfile();
                    OntResource a = (OntResource) m.getResource( NS + "a" ).as( OntResource.class );

                    a.addComment( "some info", null );
                    assertEquals( "Cardinality should be 1", 1, a.getCardinality( prof.COMMENT() ) );
                    assertEquals( "a has wrong comment", "some info", a.getComment( null ) );

                    a.addComment( "more info", null );
                    assertEquals( "Cardinality should be 2", 2, a.getCardinality( prof.COMMENT() ) );
                    iteratorTest( a.listComments( null ), new Object[] {m.createLiteral( "some info" ), m.createLiteral( "more info" )} );

                    assertTrue( "a should have comment some info", a.hasComment( "some info", null ) );
                    assertTrue( "a should have comment more info", a.hasComment( "more info", null ) );

                    a.setComment( "new info", null );
                    assertEquals( "Cardinality should be 1", 1, a.getCardinality( prof.COMMENT() ) );
                    assertEquals( "a has wrong comment", "new info", a.getComment( null ) );

                    a.removeComment( "foo", null );
                    assertEquals( "Cardinality should be 1", 1, a.getCardinality( prof.COMMENT() ) );
                    a.removeComment( "new info", null );
                    assertEquals( "Cardinality should be 0", 0, a.getCardinality( prof.COMMENT() ) );
                }
            },
            new OntTestCase( "OntResource.comment.lang", true, true, true, true ) {
                public void ontTest( OntModel m ) throws Exception {
                    OntResource a = (OntResource) m.getResource( NS + "a" ).as( OntResource.class );

                    a.addComment( "good", "EN" );
                    assertEquals( "wrong comment", "good", a.getComment( null ) );

                    a.addComment( "bon", "FR" );

                    assertEquals( "wrong comment", "good", a.getComment( "EN" ) );
                    assertEquals( "wrong comment", null, a.getComment( "EN-GB" ) );  // no literal with a specific enough language
                    assertEquals( "wrong comment", "bon", a.getComment( "FR" ) );

                    assertTrue( "a should have label good", a.hasComment( "good", "EN" ) );
                    assertTrue( "a should have label bon", a.hasComment( "bon", "FR" ) );
                    assertTrue( "a should note have label good (DE)", !a.hasComment( "good", "DE" ) );

                    a.addComment( "spiffing", "EN-GB" );
                    a.addComment( "duude", "EN-US" );

                    assertEquals( "wrong comment", "spiffing", a.getComment( "EN-GB" ) );
                    assertEquals( "wrong comment", "duude", a.getComment( "EN-US" ) );
                    assertEquals( "wrong comment", null, a.getComment( "DE" ) );

                    a.addComment( "abcdef", "AB-CD" );
                    assertEquals( "wrong comment", "abcdef", a.getComment( "AB" ) );
                    assertEquals( "wrong comment", null, a.getComment( "AB-XY" ) );

                    a.removeComment( "abcde", "AB-CD" );
                    assertEquals( "Cardinality should be 5", 5, a.getCardinality( a.getProfile().COMMENT() ) );
                    a.removeComment( "abcdef", "AB-CD" );
                    assertEquals( "Cardinality should be 4", 4, a.getCardinality( a.getProfile().COMMENT() ) );
                }
            },
            new OntTestCase( "OntResource.type (no inference)", true, true, true, true ) {
                public void ontTest( OntModel m ) throws Exception {
                    OntClass A = m.createClass( NS + "A" );
                    OntClass B = m.createClass( NS + "B" );
                    A.addSubClass( B );

                    OntResource a = (OntResource) m.getResource( NS + "a" ).as( OntResource.class );
                    assertEquals( "Cardinality of rdf:type is wrong", 0, a.getCardinality( RDF.type ) );

                    a.addRDFType( B );
                    assertEquals( "rdf:type of a is wrong", B, a.getRDFType() );
                    assertEquals( "rdf:type of a is wrong", B, a.getRDFType( false ) );

                    iteratorTest( a.listRDFTypes( false ), new Object[] {B} );       // only B since we're not using an inference model
                    iteratorTest( a.listRDFTypes( true ), new Object[] {B} );

                    a.addRDFType( A );
                    iteratorTest( a.listRDFTypes( false ), new Object[] {A,B} );
                    iteratorTest( a.listRDFTypes( true ), new Object[] {B} );

                    assertTrue( "a should not be of class A direct", !a.hasRDFType( A, true ));
                    assertTrue( "a should not be of class B direct", a.hasRDFType( B, true ));

                    OntClass C = m.createClass( NS + "C" );
                    a.setRDFType( C );
                    assertTrue( "a should be of class C", a.hasRDFType( C, false ));
                    assertTrue( "a should not be of class A", !a.hasRDFType( A, false ));
                    assertTrue( "a should not be of class B", !a.hasRDFType( B, false ));

                    a.removeRDFType( B );
                    assertEquals( "Cardinality should be 1", 1, a.getCardinality( RDF.type ) );
                    a.removeRDFType( C );
                    assertEquals( "Cardinality should be 0", 0, a.getCardinality( RDF.type ) );
                }
            },
            new OntTestCase( "OntResource.remove", true, true, true, true ) {
                public void ontTest( OntModel m ) throws Exception {
                    OntClass A = m.createClass( NS + "A" );
                    OntClass B = m.createClass( NS + "B" );
                    OntClass C = m.createClass( NS + "C" );
                    OntClass D = m.createClass( NS + "D" );
                    OntClass E = m.createClass( NS + "E" );
                    A.addSubClass( B );
                    A.addSubClass( C );
                    C.addSubClass( D );
                    C.addSubClass( E );

                    assertTrue( "super-class of E", E.hasSuperClass( C, false ) );
                    iteratorTest( A.listSubClasses(), new Object[] {B,C} );

                    C.remove();

                    assertTrue( "super-class of D", !D.hasSuperClass( C, false ) );
                    assertTrue( "super-class of E", !E.hasSuperClass( C, false ) );
                    iteratorTest( A.listSubClasses(), new Object[] {B} );
                }
            },
            new OntTestCase( "OntResource.asClass", true, true, true, true ) {
                public void ontTest( OntModel m ) throws Exception {
                    Resource r = m.createResource();
                    r.addProperty( RDF.type, m.getProfile().CLASS() );
                    OntResource or = (OntResource) r.as( OntResource.class );
                    assertFalse( "should not be annotation prop", or.isAnnotationProperty() );
                    assertFalse( "should not be all different", or.isAllDifferent() );
                    assertTrue( "should be class", or.isClass() );
                    assertFalse( "should not be property", or.isProperty() );
                    assertFalse( "should not be object property", or.isObjectProperty() );
                    assertFalse( "should not be datatype property", or.isDatatypeProperty() );
                    assertTrue( "should not be individual", owlFull() || !or.isIndividual() );
                    assertFalse( "should not be data range", or.isDataRange() );
                    assertFalse( "should not be ontology", or.isOntology() );

                    RDFNode n = or.asClass();
                    assertTrue( "Should be OntClass", n instanceof OntClass );
                }
            },
            new OntTestCase( "OntResource.asAnnotationProperty", true, true, false, false) {
                public void ontTest( OntModel m ) throws Exception {
                    if (m.getProfile().ANNOTATION_PROPERTY() == null) {
                        throw new ProfileException(null,null);
                    }
                    Resource r = m.createResource();
                    r.addProperty( RDF.type, m.getProfile().ANNOTATION_PROPERTY() );
                    OntResource or = (OntResource) r.as( OntResource.class );

                    assertTrue( "should be annotation prop", or.isAnnotationProperty() );
                    assertFalse( "should not be all different", or.isAllDifferent() );
                    assertFalse( "should not be class", or.isClass() );
                    assertTrue( "should be property", or.isProperty() );
                    assertFalse( "should not be object property", or.isObjectProperty() );
                    assertFalse( "should not be datatype property", or.isDatatypeProperty() );
                    assertFalse( "should not be individual", or.isIndividual() );
                    assertFalse( "should not be data range", or.isDataRange() );
                    assertFalse( "should not be ontology", or.isOntology() );

                    RDFNode n = or.asAnnotationProperty();
                    assertTrue( "Should be AnnotationProperty", n instanceof AnnotationProperty);
                }
            },
            new OntTestCase( "OntResource.asObjectProperty", true, true, true, false) {
                public void ontTest( OntModel m ) throws Exception {
                    if (m.getProfile().OBJECT_PROPERTY() == null) {
                        throw new ProfileException(null,null);
                    }
                    Resource r = m.createResource();
                    r.addProperty( RDF.type, m.getProfile().OBJECT_PROPERTY() );
                    OntResource or = (OntResource) r.as( OntResource.class );

                    assertFalse( "should not be annotation prop", or.isAnnotationProperty() );
                    assertFalse( "should not be all different", or.isAllDifferent() );
                    assertFalse( "should not be class", or.isClass() );
                    assertTrue( "should be property", or.isProperty() );
                    assertTrue( "should be object property", or.isObjectProperty() );
                    assertFalse( "should not be datatype property", or.isDatatypeProperty() );
                    assertFalse( "should not be individual", or.isIndividual() );
                    assertFalse( "should not be data range", or.isDataRange() );
                    assertFalse( "should not be ontology", or.isOntology() );

                    RDFNode n = or.asObjectProperty();
                    assertTrue( "Should be ObjectProperty", n instanceof ObjectProperty);
                }
            },
            new OntTestCase( "OntResource.asDatatypeProperty", true, true, true, false) {
                public void ontTest( OntModel m ) throws Exception {
                    if (m.getProfile().DATATYPE_PROPERTY() == null) {
                        throw new ProfileException(null,null);
                    }

⌨️ 快捷键说明

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