📄 getexplicitstatements.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.Statement;import org.openrdf.model.URI;import org.openrdf.model.Value;import org.openrdf.sesame.sail.RdfSchemaSource;import org.openrdf.sesame.sail.StatementIterator;import org.openrdf.sesame.sail.test.benchmark.model.BMStatement;import org.openrdf.sesame.sail.test.benchmark.pools.RdfSchemaSourcePool;/** * Tests performance of org.openrdf.sesame.sail.RdfSchemaSource.getExplicitStatements. * * @author Peter van 't Hof * @version %I%, %G% */public class GetExplicitStatements extends RdfSchemaSourceBMTestB {/*-------------+| Constructors |+-------------*/ /** * Creates a new benchmark test which tests * org.openrdf.sesame.sail.RdfSchemaSource.getExplicitStatements. * * @param rdfSchemaSource RdfSchemaSource to test. */ public GetExplicitStatements(RdfSchemaSource rdfSchemaSource) { super("getExplicitStatements", rdfSchemaSource); _needsPool = true; }/*--------+| Methods |+--------*/ // This method consists of two parts. See below. protected void _testA() { // Part one: get all statements. _startA(); _getExplicitStatements(null, null, null, true); _stopA(); /* Part two: get all statements and query any combination of subject, * predicate, object of statement and wildcards. */ Iterator i = _cutDown(RdfSchemaSourcePool.explicitStatements, 16).iterator(); while (i.hasNext()) { BMStatement statement = (BMStatement)i.next(); Resource subject = statement.getSubject(); URI predicate = statement.getPredicate(); Value object = statement.getObject(); _startA(); _getExplicitStatements(subject, null, null, true); _getExplicitStatements(null, predicate, null, true); _getExplicitStatements(null, null, object, true); _getExplicitStatements(subject, predicate, null, true); _getExplicitStatements(subject, null, object, true); _getExplicitStatements(null, predicate, object, true); _getExplicitStatements(subject, predicate, object, true); _stopA(7); } } // This method consists of three parts. See below. protected void _testB() { /* Part one: get statements. Pattern consists of values which do not * exist and wildcards. */ _startB(); _getExplicitStatements(RdfSchemaSourcePool.noSubject, null, null, false); _getExplicitStatements(null, RdfSchemaSourcePool.noPredicate, null, false); _getExplicitStatements(null, null, RdfSchemaSourcePool.noObject, false); _getExplicitStatements(RdfSchemaSourcePool.noSubject, RdfSchemaSourcePool.noPredicate, null, false); _getExplicitStatements(RdfSchemaSourcePool.noSubject, null, RdfSchemaSourcePool.noObject, false); _getExplicitStatements(null, RdfSchemaSourcePool.noPredicate, RdfSchemaSourcePool.noObject, false); _getExplicitStatements(RdfSchemaSourcePool.noSubject, RdfSchemaSourcePool.noPredicate, RdfSchemaSourcePool.noObject, false); _stopB(7); /* Part two: get statements. Pattern consists of values which do not * exist, existing values and wildcards. */ Iterator i = _cutDown(RdfSchemaSourcePool.explicitStatements, 8).iterator(); while (i.hasNext()) { BMStatement statement = (BMStatement)i.next(); Resource subject = statement.getSubject(); URI predicate = statement.getPredicate(); Value object = statement.getObject(); _startB(); _getExplicitStatements(RdfSchemaSourcePool.noSubject, predicate, null, false); _getExplicitStatements(RdfSchemaSourcePool.noSubject, null, object, false); _getExplicitStatements(RdfSchemaSourcePool.noSubject, predicate, object, false); _getExplicitStatements(null, RdfSchemaSourcePool.noPredicate, object, false); _getExplicitStatements(subject, RdfSchemaSourcePool.noPredicate, null, false); _getExplicitStatements(subject, RdfSchemaSourcePool.noPredicate, object, false); _getExplicitStatements(subject, null, RdfSchemaSourcePool.noObject, false); _getExplicitStatements(null, predicate, RdfSchemaSourcePool.noObject, false); _getExplicitStatements(subject, predicate, RdfSchemaSourcePool.noObject, false); _getExplicitStatements(RdfSchemaSourcePool.noSubject, RdfSchemaSourcePool.noPredicate, object, false); _getExplicitStatements(RdfSchemaSourcePool.noSubject, predicate, RdfSchemaSourcePool.noObject, false); _getExplicitStatements(subject, RdfSchemaSourcePool.noPredicate, RdfSchemaSourcePool.noObject, false); _stopB(12); } /* Part three: Get statements. Pattern consists of statements which do * not exist. */ Iterator l = _cutDown(RdfSchemaSourcePool.noExplicitStatements, 8).iterator(); while (l.hasNext()) { BMStatement noStatement = (BMStatement)l.next(); Resource subject = noStatement.getSubject(); URI predicate = noStatement.getPredicate(); Value object = noStatement.getObject(); _startB(); _getExplicitStatements(subject, predicate, object, false); _stopB(); } } /* Call to RdfSchemaSource. Checks if result is equal to expected result. Iterates * statements and retrieves and uses subject, predicate an object and used to * simulate realworld use. */ protected void _getExplicitStatements( Resource subject, URI predicate, Value object, boolean expected) { StatementIterator i = _rdfSchemaSource.getExplicitStatements(subject, predicate, object); if (i.hasNext() != expected) { String error = "getExplicitStatements(" + new BMStatement(subject, predicate, object) + ") should return "; if (!expected) { error += "no "; } error += "statements."; _error(error); } while (i.hasNext()) { _simulateUsage((Statement)i.next()); } i.close(); } public String toString() { return _toString("Results", "No results"); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -