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

📄 abstracttestreifier.java

📁 Jena推理机
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        R.reifyAs( N, T );
        assertTrue( "R must have T", R.hasTriple( T ) );
        assertFalse( "R must not have T2", R.hasTriple( T2 ) );
        }   
             
    public void testReifyAs()
        {
        Graph G = getGraph();
        Reifier R = G.getReifier();
        Node X = Node.createURI( "some:uri" );
        assertEquals( "node used", X, R.reifyAs( X, triple( "x R y" ) ) );
        assertEquals( "retrieves correctly", triple( "x R y" ), R.getTriple( X ) );
        }
        
    public void testAllNodes()
        {
        Reifier R = getGraph().getReifier();
        R.reifyAs( node("x"), triple( "cows eat grass" ) );
        R.reifyAs( node("y"), triple( "pigs can fly" ) );
        R.reifyAs( node("z"), triple( "dogs may bark" ) );
        assertEquals( "", nodeSet( "z y x" ), iteratorToSet( R.allNodes() ) );
        }
        
    public void testRemoveByNode()
        {
        Graph G = getGraph();
        Reifier R = G.getReifier();
        Node X = node( "x" ), Y = node( "y" );
        R.reifyAs( X, triple( "x R a" ) );
        R.reifyAs( Y, triple( "y R a" ) );
        R.remove( X, triple( "x R a" ) );
        assertFalse( "triple X has gone", R.hasTriple( X ) );
        assertEquals( "triple Y still there", triple( "y R a" ), R.getTriple( Y ) );
        }
        
    public void testRemoveFromNothing()
        {
        Graph G = getGraph();
        Reifier R = G.getReifier();
        G.delete( triple( "quint rdf:subject S" ) );
        }
    
//    public void testRemoveByTriple()
//        {
//        Graph G = getGraph();
//        Reifier R = G.getReifier();
//        Node X = node( "x" ), Y = node( "y" );
//        R.reifyAs( X, triple( "x R a" ) );
//        R.reifyAs( Y, triple( "y R a" ) );
//        R.remove( triple( "x R a" ) );
//        assertFalse( "triple X has gone", R.hasTriple( X ) );
//        assertEquals( "triple Y still there", triple( "y R a" ), R.getTriple( Y ) );            
//        }
        
    public void testException()
        {
        Graph G = getGraph();
        Reifier R = G.getReifier();
        Node X = node( "x" );
        R.reifyAs( X, triple( "x R y" ) );
        R.reifyAs( X, triple( "x R y" ) );
        try { R.reifyAs( X, triple( "x R z" ) ); fail( "did not detect already reified node" ); }
        catch (AlreadyReifiedException e) { }      
        }
        
    public void testKevinCaseA()
        {
        Graph G = getGraph( Standard );
        Node X = node( "x" ), a = node( "a" ), b = node( "b" ), c = node( "c" );
        G.add( Triple.create( X, RDF.Nodes.type, RDF.Nodes.Statement ) );
        G.getReifier().reifyAs( X, Triple.create( a, b, c ) ); 
        }
        
    public void testKevinCaseB()
        {
        Graph G = getGraph( Standard );
        Node X = node( "x" ), Y = node( "y" );
        Node a = node( "a" ), b = node( "b" ), c = node( "c" );
        G.add( Triple.create( X, RDF.Nodes.subject, Y ) );
        try
            {
            G.getReifier().reifyAs( X, Triple.create( a, b, c ) );
            fail( "X already has subject Y: cannot make it a" );
            }
        catch (CannotReifyException e)
            { pass(); }
        }

    /**
        Test that the hidden triples graph is dynamic, not static.
    */
    public void testDynamicHiddenTriples()
        {
        Graph g = getGraph( Minimal );
        Reifier r = g.getReifier();
        Graph h = getHiddenTriples( r );
        Graph wanted = graphWith
            ( 
            "x rdf:type rdf:Statement" 
            + "; x rdf:subject a"
            + "; x rdf:predicate B"
            + "; x rdf:object c"
            );
        assertTrue( h.isEmpty() );
        r.reifyAs( node( "x" ), triple( "a B c" ) );
        assertIsomorphic( wanted, h );
        }
    
    protected Graph getHiddenTriples( final Reifier r )
        {
        return new GraphBase() 
            {
            public ExtendedIterator graphBaseFind( TripleMatch m ) { return r.findEither( m, true ); }
            };
        }
            
	public void testQuadRemove()
		{
		Graph g = getGraph( Standard );
		assertEquals( 0, g.size() );
	
		Triple s = Triple.create( "x rdf:subject s" );
		Triple p = Triple.create( "x rdf:predicate p" );
		Triple o = Triple.create( "x rdf:object o" );
		Triple t = Triple.create( "x rdf:type rdf:Statement");
		g.add(s); g.add(p); g.add(o); g.add(t);
		assertEquals( 4, g.size() );

		g.delete(s); g.delete(p); g.delete(o); g.delete(t);
		assertEquals( 0, g.size() );
		}

    public void testReifierSize()
        {
        Graph g = getGraph();
        Reifier r = g.getReifier();
        assertEquals( 0, r.size() );
        }
    
    public void testEmpty()
        {
        Graph g = getGraph( Standard );
        assertTrue( g.isEmpty() );
        graphAdd( g, "x rdf:type rdf:Statement" ); assertFalse( g.isEmpty() );
        graphAdd( g, "x rdf:subject Deconstruction" ); assertFalse( g.isEmpty() );
        graphAdd( g, "x rdf:predicate rdfs:subTypeOf" ); assertFalse( g.isEmpty() );
        graphAdd( g, "x rdf:object LiteraryCriticism" ); assertFalse( g.isEmpty() );
        }
    
    public void testReifierEmptyFind()
        {
        Graph g = getGraph( Standard );
        Reifier r = g.getReifier();
        assertEquals( CollectionFactory.createHashedSet(), iteratorToSet( r.findExposed( triple( "?? ?? ??" ) ) ) );
        }

    public void testReifierFindSubject()
        { testReifierFind( "x rdf:subject S" ); }
    
    public void testReifierFindObject()
        { testReifierFind( "x rdf:object O" ); }
    
    public void testReifierFindPredicate()
        { testReifierFind( "x rdf:predicate P" ); }
    
    public void testReifierFindComplete()
        { testReifierFind( "x rdf:predicate P; x rdf:subject S; x rdf:object O; x rdf:type rdf:Statement" ); }
    
    public void testReifierFindFilter()
        { 
        Graph g = getGraph( Standard );
        Reifier r = g.getReifier();
        graphAdd( g, "s rdf:subject S" );
        assertEquals( tripleSet( "" ), iteratorToSet( r.findExposed( triple( "s otherPredicate S" ) ) ) );
        }

    protected void testReifierFind( String triples )
        { testReifierFind( triples, "?? ?? ??" ); }
    
    protected void testReifierFind( String triples, String pattern )
        {
        Graph g = getGraph( Standard );
        Reifier r = g.getReifier();
        graphAdd( g, triples );
        assertEquals(  tripleSet( triples ), iteratorToSet( r.findExposed( triple( pattern ) ) ) );
        }

    public void testQuintetBug()
        {
        String spec = "rs rdf:type rdf:Statement; foo rdf:value rs; rs rdf:subject X; rs rdf:predicate P; rs rdf:object O1; rs rdf:object O2";
        Graph g = getGraph( Standard );
        Reifier r = g.getReifier();
        try {
        graphAdd( g, spec );
        Graph wanted = getGraph( Minimal );
        graphAdd( wanted, spec );
        assertIsomorphic( wanted, g );
        }
        catch (AlreadyReifiedException e) 
        {
        if (r instanceof DBReifier) { /* System.err.println( "! Db reifier must fix over-specification problem" ); */ }
        else throw e;
        }
        }
    
    public void testBulkClearReificationTriples()
        {
        Graph g = getGraphWith( "x rdf:subject S" );
        g.getBulkUpdateHandler().removeAll();
        assertEquals( "oops: " + g.getClass(), Collections.EMPTY_SET, g.find( Node.ANY, Node.ANY, Node.ANY ).toSet() );        
        }
    
    public void testBulkClearReificationTriples2()
        {
        Graph g = getGraphWith( "x rdf:subject S; x rdf:predicate P; x rdf:object O; x rdf:type rdf:Statement" );
        g.getBulkUpdateHandler().removeAll();
        assertEquals( Collections.EMPTY_SET, g.find( Node.ANY, Node.ANY, Node.ANY ).toSet() );        
        }
    
//    public void testKevinCaseC()
//        {
//        Graph G = GraphBase.withReification( getGraph() );
//        Node X = node( "x" ), Y = node( "y" );
//        Node a = node( "a" ), b = node( "b" ), c = node( "c" );
//        G.getReifier().reifyAs( X, Triple.create( a, b, c ) );         
//        try
//            {
//            G.add( Triple.create( X, Reifier.subject, Y ) );
//            fail( "X already reifies (a, b, c): cannot give it subject Y" );
//            }
//        catch (Reifier.CannotReifyException e)
//            { /* as requried */ }
//        }
            
//    public void testQuads()
//        {
//        Node A = node( "a" ), B = node( "b" );
//        Graph G = getGraph();
//        Graph quads = getGraphWith
//            ( 
//            "a " + RDF.type + " " + RDF.Statement
//            + "; a " + RDF.subject + " x"
//            + "; a " + RDF.predicate + " R"
//            + "; a " + RDF.object + " y"
//            + "; b " + RDF.type + " " + RDF.Statement
//            + "; b " + RDF.subject + " p"
//            + "; b " + RDF.predicate + " S"
//            + "; b " + RDF.object + " q"
//            );
//        Reifier R = G.getReifier();
//        R.reifyAs( A, triple( "x R y") );
//        R.reifyAs( B, triple( "p S q" ) );
//        assertEquals( "same", quads, R.getReificationQuads() );
//        }        

    }


/*
    (c) Copyright 2003, 2004, 2005, 2006, 2007 Hewlett-Packard Development Company, LP
    All rights reserved.

    Redistribution and use in source and binary forms, with or without
    modification, are permitted provided that the following conditions
    are met:

    1. Redistributions of source code must retain the above copyright
       notice, this list of conditions and the following disclaimer.

    2. Redistributions in binary form must reproduce the above copyright
       notice, this list of conditions and the following disclaimer in the
       documentation and/or other materials provided with the distribution.

    3. The name of the author may not be used to endorse or promote products
       derived from this software without specific prior written permission.

    THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
    IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
    OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
    IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
    INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
    NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
    DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
    THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
    THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

⌨️ 快捷键说明

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