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

📄 rdfmtinferencer.java

📁 这是外国一个开源推理机
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
			"   nt.obj = t2.obj AND " +			"   t1.obj = t2.pred " +			"WHERE " +			"   t1.obj > 0 AND r.namespace > 0 AND " + 			"   t2.subj IS NULL AND " +			"   t1.subj IS NOT NULL";		return _applyRule(Rdfs7_1, query);	}	/* rdfs7.	 * 7_2. aaa rdfs:subPropertyOf bbb &&  (nt)	 *     xxx aaa yyy -->                (t1)	 *     xxx bbb yyy                    (t2)	 */	private int _applyRuleRdfs7_2()		throws SQLException	{		String query =			"SELECT DISTINCT " +				"t1.subj, nt.obj, t1.obj " +			"FROM " + NEW_TRIPLES_TABLE + " nt " +			"LEFT JOIN " + TRIPLES_TABLE + " t1 ON " +			"   nt.subj = t1.pred " +			"LEFT JOIN " + RESOURCES_TABLE + " r ON " +			"   r.id = nt.obj " +			"LEFT JOIN " + TRIPLES_TABLE + " t2 ON " +			"   t1.subj = t2.subj AND " +			"   t1.obj = t2.obj AND " +			"   nt.obj = t2.pred " +			"WHERE " +			"   nt.pred = " + _repository.rdfsSubPropertyOfId + " AND " +			"   nt.obj > 0 AND r.namespace > 0 AND " + 			"   t2.subj IS NULL AND " +			"   t1.subj IS NOT NULL";		return _applyRule(Rdfs7_2, query);	}	/* rdfs8. 	 * xxx rdf:type rdfs:Class --> xxx rdfs:subClassOf rdfs:Resource 	 * */	private int _applyRuleRdfs8()		throws SQLException	{		String query =			"SELECT DISTINCT " +				"nt.subj, " + _repository.rdfsSubClassOfId + ", " + _repository.rdfsResourceId +			" FROM " + NEW_TRIPLES_TABLE + " nt " +			"LEFT JOIN " + TRIPLES_TABLE + " t ON " +			"   nt.subj = t.subj AND " +			"   t.pred = " + _repository.rdfsSubClassOfId + " AND " +			"   t.obj = " + _repository.rdfsResourceId + " " +			"WHERE " +			"   nt.pred = " + _repository.rdfTypeId + " AND " +			"   nt.obj = " + _repository.rdfsClassId + " AND " +			"   t.subj IS NULL";		return _applyRule(Rdfs8, query);	}		/* rdfs9.	 * 9_1. xxx rdfs:subClassOf yyy &&  (nt)	 *     aaa rdf:type xxx -->        (t1)	 *     aaa rdf:type yyy            (t2)	 */	private int _applyRuleRdfs9_1()		throws SQLException	{		String query =			"SELECT DISTINCT " +				"t1.subj, " + _repository.rdfTypeId + ", " + "nt.obj " +			"FROM " + NEW_TRIPLES_TABLE + " nt " +			"LEFT JOIN " + TRIPLES_TABLE + " t1 ON " +			"   nt.subj = t1.obj AND " +			"   t1.pred = " + _repository.rdfTypeId + " " +			"LEFT JOIN " + TRIPLES_TABLE + " t2 ON " +			"   t1.subj = t2.subj AND " +			"   nt.obj = t2.obj AND " +			"   t2.pred = " + _repository.rdfTypeId + " " +			"WHERE " +			"   nt.pred = " + _repository.rdfsSubClassOfId + " AND " +			"   nt.obj > 0 AND " + // yyy needs to be a resource			"   t2.subj IS NULL AND " +			"   t1.subj IS NOT NULL";		return _applyRule(Rdfs9_1, query);	}	/* rdfs9.	 * 9_2. aaa rdf:type xxx &&          (nt)	 *     xxx rdfs:subClassOf yyy -->  (t1)	 *     aaa rdf:type yyy             (t2)	 */	private int _applyRuleRdfs9_2()		throws SQLException	{		String query =			"SELECT DISTINCT " +				"nt.subj, " + _repository.rdfTypeId + ", " + "t1.obj " +			"FROM " + NEW_TRIPLES_TABLE + " nt " +			"LEFT JOIN " + TRIPLES_TABLE + " t1 ON " +			"   nt.obj = t1.subj AND " +			"   t1.pred = " + _repository.rdfsSubClassOfId + " " +			"LEFT JOIN " + TRIPLES_TABLE + " t2 ON " +			"   nt.subj = t2.subj AND " +			"   t1.obj = t2.obj AND " +			"   t2.pred = " + _repository.rdfTypeId + " " +			"WHERE " +			"   nt.pred = " + _repository.rdfTypeId + " AND " +			"   t1.obj > 0 AND " + // yyy needs to be a resource			"   t2.subj IS NULL AND " +			"   t1.subj IS NOT NULL";		return _applyRule(Rdfs9_2, query);	}	/* rdfs10. 	 * xxx rdf:type rdfs:Class --> xxx rdfs:subClassOf xxx	 * reflexivity of rdfs:subClassOf	 */	private int _applyRuleRdfs10()		throws SQLException	{		String query =			"SELECT DISTINCT " +				"nt.subj, " + _repository.rdfsSubClassOfId + ", " + "nt.subj " +			"FROM " + NEW_TRIPLES_TABLE + " nt " +			"LEFT JOIN " + TRIPLES_TABLE + " t ON " +			"   nt.subj = t.subj AND " +			"   t.subj = t.obj AND " +			"   t.pred = " + _repository.rdfsSubClassOfId + " " +			"WHERE " +			"   nt.pred = " + _repository.rdfTypeId + " AND " +			"   nt.obj = " + _repository.rdfsClassId + " AND " +			"   t.subj IS NULL";		return _applyRule(Rdfs10, query);	}	/* rdfs11.	 * 11_1. xxx rdfs:subClassOf yyy &&  (nt)	 *     yyy rdfs:subClassOf zzz -->  (t1)	 *     xxx rdfs:subClassOf zzz      (t2)	 */	private int _applyRuleRdfs11_1()		throws SQLException	{		String query =			"SELECT DISTINCT " +				"nt.subj, " + _repository.rdfsSubClassOfId + ", " + "t1.obj " +			"FROM " + NEW_TRIPLES_TABLE + " nt " +			"LEFT JOIN " + TRIPLES_TABLE + " t1 ON " +			"   nt.obj = t1.subj AND " +			"   t1.pred = " + _repository.rdfsSubClassOfId + " " +			"LEFT JOIN " + TRIPLES_TABLE + " t2 ON " +			"   nt.subj = t2.subj AND " +			"   t1.obj = t2.obj AND " +			"   t2.pred = " + _repository.rdfsSubClassOfId + " " +			"WHERE " +			"   nt.pred = " + _repository.rdfsSubClassOfId + " AND " +			"   t1.obj > 0 AND " + // zzz needs to be a resource			"   t2.subj IS NULL AND " +			"   t1.subj IS NOT NULL";		return _applyRule(Rdfs11_1, query);	}	/* rdfs11.	 * 11_2. yyy rdfs:subClassOf zzz &&  (nt)	 *     xxx rdfs:subClassOf yyy -->  (t1)	 *     xxx rdfs:subClassOf zzz      (t2)	 */	private int _applyRuleRdfs11_2()		throws SQLException	{		String query =			"SELECT DISTINCT " +				"t1.subj, " + _repository.rdfsSubClassOfId + ", " + "nt.obj " +			"FROM " + NEW_TRIPLES_TABLE + " nt " +			"LEFT JOIN " + TRIPLES_TABLE + " t1 ON " +			"   nt.subj = t1.obj AND " +			"   t1.pred = " + _repository.rdfsSubClassOfId + " " +			"LEFT JOIN " + TRIPLES_TABLE + " t2 ON " +			"   t1.subj = t2.subj AND " +			"   nt.obj = t2.obj AND " +			"   t2.pred = " + _repository.rdfsSubClassOfId + " " +			"WHERE " +			"   nt.pred = " + _repository.rdfsSubClassOfId + " AND " +			"   nt.obj > 0 AND " + // zzz needs to be a resource			"   t2.subj IS NULL AND " +			"   t1.subj IS NOT NULL";		return _applyRule(Rdfs11_2, query);	}		/* rdfs12. 	 * xxx rdf:type rdfs:ContainerMembershipProperty -->	 *     xxx rdfs:subPropertyOf rdfs:member	 */	private int _applyRuleRdfs12()		throws SQLException	{		String query =			"SELECT DISTINCT " +				"nt.subj, " + _repository.rdfsSubPropertyOfId + ", " + _repository.rdfsMemberId +			" FROM " + NEW_TRIPLES_TABLE + " nt " +			"LEFT JOIN " + TRIPLES_TABLE + " t ON " +			"   nt.subj = t.subj AND " +			"   t.obj = " + _repository.rdfsMemberId + " AND " +			"   t.pred = " + _repository.rdfsSubPropertyOfId + " " +			"WHERE " +			"   nt.pred = " + _repository.rdfTypeId + " AND " +			"   nt.obj = " + _repository.rdfsContainerMembershipPropertyId +			" AND " +			"   t.subj IS NULL";		return _applyRule(Rdfs12, query);	}	/* rdfs13.  xxx rdf:type rdfs:Datatype --> xxx rdfs:subClassOf rdfs:Literal	 */	private int _applyRuleRdfs13()		throws SQLException	{		String query =			"SELECT DISTINCT " +				"nt.subj, " + _repository.rdfsSubClassOfId + ", " + _repository.rdfsLiteralId +			" FROM " + NEW_TRIPLES_TABLE + " nt " +			"LEFT JOIN " + TRIPLES_TABLE + " t ON " +			"   nt.subj = t.subj AND " +			"   t.obj = " + _repository.rdfsLiteralId + " AND " +			"   t.pred = " + _repository.rdfsSubClassOfId + " " +			"WHERE " +			"   nt.pred = " + _repository.rdfTypeId + " AND " +			"   nt.obj = " + _repository.rdfsDatatypeId +			" AND " +			"   t.subj IS NULL";		return _applyRule(Rdfs13, query);	}	/* X1. xxx rdf:_* yyy -->	 *     rdf:_* rdf:type rdfs:ContainerMembershipProperty	 *	 * This is an extra rule for list membership properties (_1, _2, _3,	 * ...). The RDF MT does not specificy a production for this, but specificies this as a non-closed	 * set of axioms (section 3.1).	 */	private int _applyRuleX1()		throws SQLException	{		int rdfNsId = _repository._getNamespaceId(RDF.NAMESPACE);		if (rdfNsId == 0) {			// Namespace not used by any resource.			return 0;		}		// Create like pattern matching localnames starting with an underscore		String likePattern;		if (_rdbms.getSearchStringEscape() != null) {			// Use default rdbms escape character			likePattern = "'" + _rdbms.getSearchStringEscape() + "_%' ";		}		else if (_rdbms.supportsLikeEscapeClause()) {			// Specify backslash as escape character			likePattern = "'\\_%' ESCAPE '\\' ";		}		else {			throw new SQLException("Unable to create like pattern; no escape character available");		}		// Create query		String query =			"SELECT DISTINCT " +				"nt.pred, " + _repository.rdfTypeId + ", " +				_repository.rdfsContainerMembershipPropertyId + " " +			"FROM " + NEW_TRIPLES_TABLE + " nt " +			"LEFT JOIN " + RESOURCES_TABLE + " r ON " +				"nt.pred = r.id AND " +				"r.namespace = " + rdfNsId + " AND " +				"r.localname LIKE " + likePattern +			"LEFT JOIN " + TRIPLES_TABLE + " t ON " +				"nt.pred = t.subj AND " +				"t.pred = " + _repository.rdfTypeId + " AND " +				"t.obj = " + _repository.rdfsContainerMembershipPropertyId + " " +			"WHERE " +				"r.id IS NOT NULL AND " +				"t.subj IS NULL";		return _applyRule(RX1, query);	}	private int _applyRule(int ruleNo, String query)		throws SQLException	{		if (!_checkRule[ruleNo]) {			return 0;		}		//ThreadLog.trace("Evaluating rule " + RULENAMES[ruleNo]);		long startTime = System.currentTimeMillis();		int nofInferred = 0;		_prepareInsertConnection();		Connection queryCon = _rdbms.getConnection();		java.sql.Statement querySt = queryCon.createStatement();		ResultSet rs = querySt.executeQuery(query);		while (rs.next()) {			_insertSt.setInt(1, _repository._getNextStatementId()); // id			_insertSt.setInt(2, rs.getInt(1)); // subj			_insertSt.setInt(3, rs.getInt(2)); // pred			_insertSt.setInt(4, rs.getInt(3)); // obj			//_insertSt.addBatch();			_insertSt.executeUpdate();			nofInferred++;		}		rs.close();		querySt.close();		queryCon.close();		_closeInsertConnection(nofInferred > 0);		//ThreadLog.trace(nofInferred + " stats inferred");		if (nofInferred > 0) {			_ruleCount[ruleNo] += nofInferred;			// Copy the newly inferred statements from INFERRED_TABLE to			// ALL_INFERRED_TABLE...			_rdbms.copyRows(INFERRED_TABLE, ALL_INFERRED_TABLE);			// ...and to TRIPLES_TABLE.			_rdbms.copyRows(INFERRED_TABLE, TRIPLES_TABLE);			// Clear INFERRED_TABLE			_rdbms.clearTable(INFERRED_TABLE);		}		long endTime = System.currentTimeMillis();		_ruleTime[ruleNo] += (endTime - startTime);		if (nofInferred > 0) {			// Check which rules are triggered by this one.			boolean[] triggers = TRIGGERS[ruleNo];			for (int i = 0; i < RULECOUNT; i++) {				if (triggers[i] == true) {					_checkRuleNextIter[i] = true;				}			}		}		return nofInferred;	}}

⌨️ 快捷键说明

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