📄 getstatements.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.RdfSource;import org.openrdf.sesame.sail.StatementIterator;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.getStatements. * * @author Peter van 't Hof * @version %I%, %G% */public class GetStatements extends RdfSourceBMTestB {/*-------------+| Constructors |+-------------*/ /** * Creates a new benchmark test which tests * org.openrdf.sesame.sail.RdfSource.getStatements. * * @param rdfSource RdfSource to test. */ public GetStatements(RdfSource rdfSource) { super("getStatements", rdfSource); _needsPool = true; }/*--------+| Methods |+--------*/ // This method consists of two parts. See below. protected void _testA() { // Part one: get all statements. _startA(); _getStatements(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(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(); _getStatements(subject, null, null, true); _getStatements(null, predicate, null, true); _getStatements(null, null, object, true); _getStatements(subject, predicate, null, true); _getStatements(subject, null, object, true); _getStatements(null, predicate, object, true); _getStatements(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(); _getStatements(RdfSourcePool.noSubject, null, null, false); _getStatements(null, RdfSourcePool.noPredicate, null, false); _getStatements(null, null, RdfSourcePool.noObject, false); _getStatements(RdfSourcePool.noSubject, RdfSourcePool.noPredicate, null, false); _getStatements(RdfSourcePool.noSubject, null, RdfSourcePool.noObject, false); _getStatements(null, RdfSourcePool.noPredicate, RdfSourcePool.noObject, false); _getStatements(RdfSourcePool.noSubject, RdfSourcePool.noPredicate, RdfSourcePool.noObject, false); _stopB(7); /* Part two: get statements. Pattern consists of values which do not * exist, existing values and wildcards. */ 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(); _getStatements(RdfSourcePool.noSubject, predicate, null, false); _getStatements(RdfSourcePool.noSubject, null, object, false); _getStatements(RdfSourcePool.noSubject, predicate, object, false); _getStatements(null, RdfSourcePool.noPredicate, object, false); _getStatements(subject, RdfSourcePool.noPredicate, null, false); _getStatements(subject, RdfSourcePool.noPredicate, object, false); _getStatements(subject, null, RdfSourcePool.noObject, false); _getStatements(null, predicate, RdfSourcePool.noObject, false); _getStatements(subject, predicate, RdfSourcePool.noObject, false); _getStatements(RdfSourcePool.noSubject, RdfSourcePool.noPredicate, object, false); _getStatements(RdfSourcePool.noSubject, predicate, RdfSourcePool.noObject, false); _getStatements(subject, RdfSourcePool.noPredicate, RdfSourcePool.noObject, false); _stopB(12); } /* Part three: Get statements. Pattern consists of statements which do * not exist. */ Iterator l = _cutDown(RdfSourcePool.noStatements, 8).iterator(); while (l.hasNext()) { BMStatement noStatement = (BMStatement)l.next(); Resource subject = noStatement.getSubject(); URI predicate = noStatement.getPredicate(); Value object = noStatement.getObject(); _startB(); _getStatements(subject, predicate, object, false); _stopB(); } } /* Call to RdfSource. 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 _getStatements( Resource subject, URI predicate, Value object, boolean expected) { StatementIterator i = _rdfSource.getStatements(subject, predicate, object); if (i.hasNext() != expected) { String error = "getStatements(" + 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 + -