📄 hasstatement.java
字号:
/* Sesame - Storage and Querying architecture for RDF and RDF Schema * Copyright (C) 2001-2005 Aduna * * Contact: * Aduna * Prinses Julianaplein 14 b * 3817 CS Amersfoort * The Netherlands * tel. +33 (0)33 465 99 87 * fax. +33 (0)33 465 99 87 * * http://aduna.biz/ * http://www.openrdf.org/ * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */package org.openrdf.sesame.sail.test.benchmark.tests;import java.util.Iterator;import org.openrdf.model.Resource;import org.openrdf.model.URI;import org.openrdf.model.Value;import org.openrdf.sesame.sail.RdfSource;import org.openrdf.sesame.sail.test.benchmark.model.BMStatement;import org.openrdf.sesame.sail.test.benchmark.pools.RdfSourcePool;/** * Tests performance of org.openrdf.sesame.sail.RdfSource.hasStatement. * * @author Peter van 't Hof * @version %I%, %G% */public class HasStatement extends RdfSourceBMTestB {/*-------------+| Constructors |+-------------*/ /** * Creates a new benchmark test which tests * org.openrdf.sesame.sail.RdfSourcehasStatement. * * @param rdfSource RdfSource to test. */ public HasStatement(RdfSource rdfSource) { super("hasStatement", rdfSource); _needsPool = true; }/*--------+| Methods |+--------*/ // This method consists of two parts. See below. protected void _testA() { // Part one: query if a(!) statement exist. _startA(); _hasStatement(null, null, null, true); _stopA(); /* Part two: get all statements and query if any combination of subject, * predicate, object of statement and wildcards exist. */ Iterator i = _cutDown(RdfSourcePool.statements, 16).iterator(); while (i.hasNext()) { BMStatement statement = (BMStatement)i.next(); Resource subject = statement.getSubject(); URI predicate = statement.getPredicate(); Value object = statement.getObject(); _startA(); _hasStatement(subject, null, null, true); _hasStatement(null, predicate, null, true); _hasStatement(null, null, object, true); _hasStatement(subject, predicate, null, true); _hasStatement(subject, null, object, true); _hasStatement(null, predicate, object, true); _hasStatement(subject, predicate, object, true); _stopA(7); } } // This method consist of two parts. See below. protected void _testB() { /* Part one: query if pattern consisting of values which does not exist * and wildcards exist. */ _startB(); _hasStatement(RdfSourcePool.noSubject, null, null, false); _hasStatement(null, RdfSourcePool.noPredicate, null, false); _hasStatement(null, null, RdfSourcePool.noObject, false); _hasStatement(RdfSourcePool.noSubject, RdfSourcePool.noPredicate, null, false); _hasStatement(RdfSourcePool.noSubject, null, RdfSourcePool.noObject, false); _hasStatement(null, RdfSourcePool.noPredicate, RdfSourcePool.noObject, false); _hasStatement(RdfSourcePool.noSubject, RdfSourcePool.noPredicate, RdfSourcePool.noObject, false); _stopB(7); /* Part two: query if pattern consisting of values which do not exist, * existing values and wildcards exists. */ Iterator i = _cutDown(RdfSourcePool.statements, 8).iterator(); while (i.hasNext()) { BMStatement statement = (BMStatement)i.next(); Resource subject = statement.getSubject(); URI predicate = statement.getPredicate(); Value object = statement.getObject(); _startB(); _hasStatement(RdfSourcePool.noSubject, null, object, false); _hasStatement(RdfSourcePool.noSubject, predicate, null, false); _hasStatement(RdfSourcePool.noSubject, predicate, object, false); _hasStatement(subject, RdfSourcePool.noPredicate, object, false); _hasStatement(null, RdfSourcePool.noPredicate, object, false); _hasStatement(subject, RdfSourcePool.noPredicate, null, false); _hasStatement(subject, predicate, RdfSourcePool.noObject, false); _hasStatement(null, predicate, RdfSourcePool.noObject, false); _hasStatement(subject, null, RdfSourcePool.noObject, false); _hasStatement(RdfSourcePool.noSubject, RdfSourcePool.noPredicate, object, false); _hasStatement(RdfSourcePool.noSubject, predicate, RdfSourcePool.noObject, false); _hasStatement(subject, RdfSourcePool.noPredicate, RdfSourcePool.noObject, false); _stopB(12); } /* Part three: query if pattern consisting of statements who do not exist * exists. */ Iterator j = _cutDown(RdfSourcePool.noStatements, 8).iterator(); while (j.hasNext()) { BMStatement noStatement = (BMStatement)j.next(); Resource subject = noStatement.getSubject(); URI predicate = noStatement.getPredicate(); Value object = noStatement.getObject(); _startB(); _hasStatement(subject, predicate, object, false); _stopB(); } } // Call to RdfSource. Checks if result is equal to expected result. protected void _hasStatement( Resource subject, URI predicate, Value object, boolean expected) { if (expected != _rdfSource.hasStatement(subject, predicate, object)) { _error( "hasStatement(" + new BMStatement(subject, predicate, object) + ") should be " + expected + "."); } } public String toString() { return _toString("True", "False"); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -