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

📄 rdfmtdependencyinferencer.java

📁 这是外国一个开源推理机
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*  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.sailimpl.rdbms;import java.sql.SQLException;import org.openrdf.util.log.ThreadLog;import org.openrdf.vocabulary.RDF;/** * Dependency inferencer that infers the depencies between statements based on * the rules from the RDF Model Theory Recommendation (10 February 2004). * See http://www.w3.org/TR/2004/REC-rdf-mt-20040210/. The dependencies are * stored in the DEPEND_TABLE. This inferencer operates directly on the database * used by the RdfSchemaRepository. **/public class RdfMTDependencyInferencer implements TableNames {/*----------------------------------------+| Variables                               |+----------------------------------------*/	protected RdfSchemaRepository _sail;	protected RDBMS _rdbms;/*----------------------------------------+| Constructors                            |+----------------------------------------*/	public RdfMTDependencyInferencer(RdfSchemaRepository sail, RDBMS rdbms) {		_sail = sail;		_rdbms = rdbms;	}/*----------------------------------------+| Methods                                 |+----------------------------------------*/	/**	 * Marks all statements that are in ALL_NEW_TRIPLES_TABLE as axioms.	 **/	public void markAxioms()		throws SQLException	{		ThreadLog.trace("adding dependencies for axioms");		_rdbms.executeUpdate(				"INSERT INTO " + DEPEND_TABLE +				" SELECT id, 0, 0 FROM " + ALL_NEW_TRIPLES_TABLE);		ThreadLog.trace("dependencies for axioms added");	}	/**	 * Processes the new statements that are in ALL_NEW_TRIPLES_TABLE and	 * records there dependencies in the DEPEND_TABLE.	 **/	public void processNewStatements()		throws SQLException	{		ThreadLog.trace("adding dependencies for new statements");		_addRuleRdf1Dependencies();		_addRuleRdfs2Dependencies();		_addRuleRdfs3Dependencies();		_addRuleRdfs4aDependencies();		_addRuleRdfs4bDependencies();		_addRuleRdfs5Dependencies();		_addRuleRdfs6Dependencies();		_addRuleRdfs7Dependencies();		_addRuleRdfs8Dependencies();		_addRuleRdfs9Dependencies();		_addRuleRdfs10Dependencies();		_addRuleRdfs11Dependencies();		_addRuleRdfs12Dependencies();		_addRuleRdfs13Dependencies();		_addRuleX1Dependencies();		ThreadLog.trace("dependencies for new statements added");	}			/* 1. xxx aaa yyy --> aaa rdf:type rdf:Property */	protected void _addRuleRdf1Dependencies()		throws SQLException	{		_rdbms.executeUpdate(				"INSERT INTO " + DEPEND_TABLE + 				" SELECT t.id, dep1.id, 0 FROM " +				ALL_NEW_TRIPLES_TABLE + " dep1, " +				TRIPLES_TABLE + " t " +				"WHERE dep1.pred = t.subj" +				" AND t.pred = " + _sail.rdfTypeId +				" AND t.obj = " + _sail.rdfPropertyId +				" AND dep1.id <> t.id");	}	/* 2. xxx aaa yyy && aaa rdfs:domain zzz --> xxx rdf:type zzz */	protected void _addRuleRdfs2Dependencies()		throws SQLException	{		// xxx aaa yyy in ALL_NEW_TRIPLES_TABLE:		_rdbms.executeUpdate(				"INSERT INTO " + DEPEND_TABLE + 				" SELECT t.id, dep1.id, dep2.id FROM " +				ALL_NEW_TRIPLES_TABLE + " dep1, " +				TRIPLES_TABLE + " dep2, " +				TRIPLES_TABLE + " t " +				"WHERE dep1.pred = dep2.subj" +				" AND dep1.subj = t.subj" +				" AND dep2.pred = " + _sail.rdfsDomainId +				" AND dep2.obj = t.obj" + 				" AND t.pred = " + _sail.rdfTypeId +				" AND dep1.id <> t.id");		// aaa rdfs:domain zzz in ALL_NEW_TRIPLES_TABLE:		_rdbms.executeUpdate(				"INSERT INTO " + DEPEND_TABLE + 				" SELECT t.id, dep1.id, dep2.id FROM " +				TRIPLES_TABLE + " dep1, " +				ALL_NEW_TRIPLES_TABLE + " dep2, " +				TRIPLES_TABLE + " t " +				"WHERE dep1.pred = dep2.subj" +				" AND dep1.subj = t.subj" +				" AND dep2.pred = " + _sail.rdfsDomainId +				" AND dep2.obj = t.obj" + 				" AND t.pred = " + _sail.rdfTypeId +				" AND dep1.id <> t.id");	}	/* xxx aaa uuu && aaa rdfs:range zzz --> uuu rdf:type zzz */	protected void _addRuleRdfs3Dependencies()		throws SQLException	{		// xxx aaa uuu in ALL_NEW_TRIPLES_TABLE:		_rdbms.executeUpdate(				"INSERT INTO " + DEPEND_TABLE + 				" SELECT t.id, dep1.id, dep2.id FROM " +				ALL_NEW_TRIPLES_TABLE + " dep1, " +				TRIPLES_TABLE + " dep2, " +				TRIPLES_TABLE + " t " +				"WHERE dep1.pred = dep2.subj" +				" AND dep1.obj = t.subj" +				" AND dep2.pred = " + _sail.rdfsRangeId +				" AND dep2.obj = t.obj" + 				" AND t.pred = " + _sail.rdfTypeId +				" AND dep1.id <> t.id");		// aaa rdfs:range zzz in ALL_NEW_TRIPLES_TABLE:		_rdbms.executeUpdate(				"INSERT INTO " + DEPEND_TABLE + 				" SELECT t.id, dep1.id, dep2.id FROM " +				TRIPLES_TABLE + " dep1, " +				ALL_NEW_TRIPLES_TABLE + " dep2, " +				TRIPLES_TABLE + " t " +				"WHERE dep1.pred = dep2.subj" +				" AND dep1.obj = t.subj" +				" AND dep2.pred = " + _sail.rdfsRangeId +				" AND dep2.obj = t.obj" + 				" AND t.pred = " + _sail.rdfTypeId +				" AND dep1.id <> t.id");	}	/* xxx aaa yyy --> xxx rdf:type rdfs:Resource */	protected void _addRuleRdfs4aDependencies()		throws SQLException	{		_rdbms.executeUpdate(				"INSERT INTO " + DEPEND_TABLE + 				" SELECT t.id, dep1.id, 0 FROM " +				ALL_NEW_TRIPLES_TABLE + " dep1, " +				TRIPLES_TABLE + " t " +				"WHERE dep1.subj = t.subj" +				" AND t.pred = " + _sail.rdfTypeId +				" AND t.obj = " + _sail.rdfsResourceId +				" AND dep1.id <> t.id");	}	/* xxx aaa uuu --> uuu rdf:type rdfs:Resource */	protected void _addRuleRdfs4bDependencies()		throws SQLException	{		_rdbms.executeUpdate(				"INSERT INTO " + DEPEND_TABLE + 				" SELECT t.id, dep1.id, 0 FROM " +				ALL_NEW_TRIPLES_TABLE + " dep1, " +				TRIPLES_TABLE + " t " +				//FIXME: does this extra condition speed things up?:				"WHERE dep1.obj > 0" + // only applies to resources				" AND dep1.obj = t.subj" +				" AND t.pred = " + _sail.rdfTypeId +				" AND t.obj = " + _sail.rdfsResourceId +				" AND dep1.id <> t.id");	}	/* aaa rdfs:subPropertyOf bbb && bbb rdfs:subPropertyOf ccc -->	 * aaa rdfs:subPropertyOf ccc	 */	protected void _addRuleRdfs5Dependencies()		throws SQLException	{		// aaa rdfs:subPropertyOf bbb in ALL_NEW_TRIPLES_TABLE:		_rdbms.executeUpdate(				"INSERT INTO " + DEPEND_TABLE +				" SELECT t.id, dep1.id, dep2.id FROM " +				ALL_NEW_TRIPLES_TABLE + " dep1, " +				TRIPLES_TABLE + " dep2, " +				TRIPLES_TABLE + " t " +				"WHERE dep1.pred = " + _sail.rdfsSubPropertyOfId +				" AND dep2.pred = " + _sail.rdfsSubPropertyOfId +				" AND t.pred = " + _sail.rdfsSubPropertyOfId +				" AND dep1.subj = t.subj" +				" AND dep1.obj = dep2.subj" +				" AND dep2.obj = t.obj" +				" AND dep1.id <> t.id" +				" AND dep2.id <> t.id");		// bbb rdfs:subPropertyOf ccc in ALL_NEW_TRIPLES_TABLE:		_rdbms.executeUpdate(				"INSERT INTO " + DEPEND_TABLE +				" SELECT t.id, dep1.id, dep2.id FROM " +

⌨️ 快捷键说明

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