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

📄 rdfmtinferencer.java

📁 这是外国一个开源推理机
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
		}		int nofInferred = 1;		ThreadLog.trace("starting inferencing");		try {			while (nofInferred > 0) {				iteration++;				// check which rules need applying this iteration:				_prepareNextIteration();					// Apply inferencing to all statements in newTriples.				// Each rule will insert any newly inferred statements into				// INFERRED_TABLE and ALL_INFERRED_TABLE.					nofInferred = 0;					// Batch-oriented processing:				nofInferred += _applyRuleRdf1();				nofInferred += _applyRuleRdfs2_1();				nofInferred += _applyRuleRdfs2_2();				nofInferred += _applyRuleRdfs3_1();				nofInferred += _applyRuleRdfs3_2();				nofInferred += _applyRuleRdfs4a();				nofInferred += _applyRuleRdfs4b();				nofInferred += _applyRuleRdfs5_1();				nofInferred += _applyRuleRdfs5_2();				nofInferred += _applyRuleRdfs6();				nofInferred += _applyRuleRdfs6();				nofInferred += _applyRuleRdfs7_1();				nofInferred += _applyRuleRdfs7_2();				nofInferred += _applyRuleRdfs8();				nofInferred += _applyRuleRdfs9_1();				nofInferred += _applyRuleRdfs9_2();				nofInferred += _applyRuleRdfs10();				nofInferred += _applyRuleRdfs11_1();				nofInferred += _applyRuleRdfs11_2();				nofInferred += _applyRuleRdfs12();				nofInferred += _applyRuleRdfs13();				nofInferred += _applyRuleX1();					_totalInferred += nofInferred;					// The triples from NEW_TRIPLES_TABLE have been processed,				// continue with the newly inferred triples from ALL_INFERRED_TABLE					_rdbms.clearTable(NEW_TRIPLES_TABLE);					if (nofInferred > 0) {					_rdbms.copyRows(ALL_INFERRED_TABLE, NEW_TRIPLES_TABLE);					_rdbms.copyRows(ALL_INFERRED_TABLE, ALL_NEW_TRIPLES_TABLE);						_rdbms.clearTable(ALL_INFERRED_TABLE);						_rdbms.optimizeTable(NEW_TRIPLES_TABLE);					_rdbms.optimizeTable(TRIPLES_TABLE);				}					ThreadLog.trace("iteration " + iteration + " done; " +					"inferred " + nofInferred + " new statements");			}				_rdbms.optimizeTable(ALL_NEW_TRIPLES_TABLE);		}		catch (SQLException e) {			throw new SailInternalException(e);		}		// Print some statistics		ThreadLog.trace("---RdfMTInferencer statistics:---");		ThreadLog.trace("total statements inferred = " + _totalInferred);		for (int i = 0; i < RULECOUNT; i++) {			ThreadLog.trace(					"rule " + RULENAMES[i] + ": time=" + _ruleTime[i] +					";\t#inferred=" + _ruleCount[i]);		}		ThreadLog.trace("---end of statistics:---");	}	private void _prepareNextIteration() {		for (int i = 0; i < RULECOUNT; i++) {			_checkRule[i] = _checkRuleNextIter[i];			// reset for next iteration:			_checkRuleNextIter[i] = false;		}	}	/* rdf1. 	 * xxx aaa yyy --> aaa rdf:type rdf:Property	 */	private int _applyRuleRdf1()		throws SQLException	{		String query =			"SELECT DISTINCT " +				"nt.pred, " + _repository.rdfTypeId + ", " + _repository.rdfPropertyId +			" FROM " + NEW_TRIPLES_TABLE + " nt " +			"LEFT JOIN " + TRIPLES_TABLE + " t ON " +			"   nt.pred = t.subj AND " +			"   t.pred = " + _repository.rdfTypeId + " AND " +			"   t.obj = " + _repository.rdfPropertyId + " " +			"WHERE " +			"   t.subj IS NULL";		return _applyRule(Rdf1, query);	}		/* rdf2.	 * uuu aaa lll --> _:nnn rdf:type rdf:XMLLiteral	 * (lll is a wellformed XML literal)	 * Rule not implemented.  	 */	/* rdfs1.	 * uuu aaa lll --> _:nnn rdf:type rdfs:Literal	 * (lll is a plain literal)	 * Rule not implemented.	 */		/* rdfs2.	 * 2_1. xxx aaa yyy &&           (nt)	 *      aaa rdfs:domain zzz -->  (t1)	 *      xxx rdf:type zzz         (t2)	 */	private int _applyRuleRdfs2_1()		throws SQLException	{		String query =			"SELECT DISTINCT " +				"nt.subj, " + _repository.rdfTypeId + ", " + "t1.obj " +			"FROM " + NEW_TRIPLES_TABLE + " nt " +			"LEFT JOIN " + TRIPLES_TABLE + " t1 ON " +			"   nt.pred = t1.subj AND " +			"   t1.pred = " + _repository.rdfsDomainId + " " +			"LEFT JOIN " + TRIPLES_TABLE + " t2 ON " +			"   nt.subj = t2.subj AND " +			"   t1.obj = t2.obj AND " +			"   t2.pred = " + _repository.rdfTypeId + " " +			"WHERE " +			"   t1.obj > 0 AND " + // domain class needs to be a resource			"   t2.subj IS NULL AND " +			"   t1.subj IS NOT NULL";		return _applyRule(Rdfs2_1, query);	}	/* rdfs2.	 * 2_2. aaa rdfs:domain zzz &&  (nt)	 *     xxx aaa yyy -->         (t1)	 *     xxx rdf:type zzz        (t2)	 */	private int _applyRuleRdfs2_2()		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.pred " +			"LEFT JOIN " + TRIPLES_TABLE + " t2 ON " +			"   nt.obj = t2.obj AND " +			"   t1.subj = t2.subj AND " +			"   t2.pred = " + _repository.rdfTypeId + " " +			"WHERE " +			"   nt.pred = " + _repository.rdfsDomainId + " AND " +			"   nt.obj > 0 AND " + // domain class needs to be a resource			"   t2.subj IS NULL AND " +			"   t1.subj IS NOT NULL";		return _applyRule(Rdfs2_2, query);	}	/* rdfs3.	 * 3_1. xxx aaa uuu &&          (nt)	 *     aaa rdfs:range zzz -->  (t1)	 *     uuu rdf:type zzz        (t2)	 */	private int _applyRuleRdfs3_1()		throws SQLException	{		String query =			"SELECT DISTINCT " +				"nt.obj, " + _repository.rdfTypeId + ", " + "t1.obj " +			"FROM " + NEW_TRIPLES_TABLE + " nt " +			"LEFT JOIN " + TRIPLES_TABLE + " t1 ON " +			"   nt.pred = t1.subj AND " +			"   t1.pred = " + _repository.rdfsRangeId + " " +			"LEFT JOIN " + TRIPLES_TABLE + " t2 ON " +			"   nt.obj = t2.subj AND " +			"   t1.obj = t2.obj AND " +			"   t2.pred = " + _repository.rdfTypeId + " " +			"WHERE " +			"   nt.obj > 0 AND " + // object needs to be a resource			"   t1.obj > 0 AND " + // range class needs to be a resource			"   t2.subj IS NULL AND " +			"   t1.subj IS NOT NULL";		return _applyRule(Rdfs3_1, query);	}	/* rdfs3.	 * 3_2. aaa rdfs:range zzz &&  (nt)	 *     xxx aaa uuu -->        (t1)	 *     uuu rdf:type zzz       (t2)	 */	private int _applyRuleRdfs3_2()		throws SQLException	{		String query =			"SELECT DISTINCT " +				"t1.obj, " + _repository.rdfTypeId + ", " + "nt.obj " +			"FROM " + NEW_TRIPLES_TABLE + " nt " +			"LEFT JOIN " + TRIPLES_TABLE + " t1 ON " +			"   nt.subj = t1.pred " +			"LEFT JOIN " + TRIPLES_TABLE + " t2 ON " +			"   t1.obj = t2.subj AND " +			"   nt.obj = t2.obj AND " +			"   t2.pred = " + _repository.rdfTypeId + " " +			"WHERE " +			"   t1.obj > 0 AND " + // object needs to be a resource			"   nt.obj > 0 AND " + // range class needs to be a resource			"   nt.pred = " + _repository.rdfsRangeId + " AND " +			"   t2.subj IS NULL AND " +			"   t1.subj IS NOT NULL";		return _applyRule(Rdfs3_2, query);	}	/* rdfs4a.	 * xxx aaa yyy --> xxx rdf:type rdfs:Resource	 */	private int _applyRuleRdfs4a()		throws SQLException	{		String query =			"SELECT DISTINCT " +				"nt.subj, " + _repository.rdfTypeId + ", " + _repository.rdfsResourceId +			" FROM " + NEW_TRIPLES_TABLE + " nt " +			"LEFT JOIN " + TRIPLES_TABLE + " t ON " +			"   nt.subj = t.subj AND " +			"   t.pred = " + _repository.rdfTypeId + " AND " +			"   t.obj = " + _repository.rdfsResourceId + " " +			"WHERE " +			"   t.subj IS NULL";		return _applyRule(Rdfs4a, query);	}	/* rdfs4b. 	 * xxx aaa uuu --> uuu rdf:type rdfs:Resource	 */	private int _applyRuleRdfs4b()		throws SQLException	{		String query =			"SELECT DISTINCT " +				"nt.obj, " + _repository.rdfTypeId + ", " + _repository.rdfsResourceId +			" FROM " + NEW_TRIPLES_TABLE + " nt " +			"LEFT JOIN " + TRIPLES_TABLE + " t ON " +			"   nt.obj = t.subj AND " +			"   t.pred = " + _repository.rdfTypeId + " AND " +			"   t.obj = " + _repository.rdfsResourceId + " " +			"WHERE " +			"   nt.obj > 0 AND " + // object needs to be a resource			"   t.subj IS NULL";		return _applyRule(Rdfs4b, query);	}	/* rdfs5.	 * 5_1. aaa rdfs:subPropertyOf bbb &&   (nt)	 *     bbb rdfs:subPropertyOf ccc -->  (t1)	 *     aaa rdfs:subPropertyOf ccc      (t2)	 */	private int _applyRuleRdfs5_1()		throws SQLException	{		String query =			"SELECT DISTINCT " +				"nt.subj, " + _repository.rdfsSubPropertyOfId + ", " + "t1.obj " +			"FROM " + NEW_TRIPLES_TABLE + " nt " +			"LEFT JOIN " + TRIPLES_TABLE + " t1 ON " +			"   nt.obj = t1.subj AND " +			"   t1.pred = " + _repository.rdfsSubPropertyOfId + " " +			"LEFT JOIN " + TRIPLES_TABLE + " t2 ON " +			"   nt.subj = t2.subj AND " +			"   t1.obj = t2.obj AND " +			"   t2.pred = " + _repository.rdfsSubPropertyOfId + " " +			"WHERE " +			"   nt.pred = " + _repository.rdfsSubPropertyOfId + " AND " +			"   t1.obj > 0 AND " + // ccc needs to be a resource			"   t2.subj IS NULL AND " +			"   t1.subj IS NOT NULL";		return _applyRule(Rdfs5_1, query);	}	/* rdfs5.	 * 5_2. bbb rdfs:subPropertyOf ccc && (nt)	 *     aaa rdfs:subPropertyOf bbb -->  (t1)	 *     aaa rdfs:subPropertyOf ccc      (t2)	 */	private int _applyRuleRdfs5_2()		throws SQLException	{		String query =			"SELECT DISTINCT " +				"t1.subj, " + _repository.rdfsSubPropertyOfId + ", " + "nt.obj " +			"FROM " + NEW_TRIPLES_TABLE + " nt " +			"LEFT JOIN " + TRIPLES_TABLE + " t1 ON " +			"   nt.subj = t1.obj AND " +			"   t1.pred = " + _repository.rdfsSubPropertyOfId + " " +			"LEFT JOIN " + TRIPLES_TABLE + " t2 ON " +			"   nt.obj = t2.obj AND " +			"   t1.subj = t2.subj AND " +			"   t2.pred = " + _repository.rdfsSubPropertyOfId + " " +			"WHERE " +			"   nt.pred = " + _repository.rdfsSubPropertyOfId + " AND " +			"   nt.obj > 0 AND " + // ccc needs to be a resource			"   t2.subj IS NULL AND " +			"   t1.subj IS NOT NULL";		return _applyRule(Rdfs5_2, query);	}	/* rdfs6. 	 * xxx rdf:type rdf:Property --> xxx rdfs:subPropertyOf xxx	 * reflexivity of rdfs:subPropertyOf	 */	private int _applyRuleRdfs6()		throws SQLException	{		String query =			"SELECT DISTINCT " +				"nt.subj, " + _repository.rdfsSubPropertyOfId + ", " + "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.rdfsSubPropertyOfId + " " +			"WHERE " +			"   nt.pred = " + _repository.rdfTypeId + " AND " +			"   nt.obj = " + _repository.rdfPropertyId + " AND " +			"   t.subj IS NULL";		return _applyRule(Rdfs6, query);	}	/* rdfs7.	 * 7_1. xxx aaa yyy &&                  (nt)	 *     aaa rdfs:subPropertyOf bbb -->  (t1)	 *     xxx bbb yyy                     (t2)	 */	private int _applyRuleRdfs7_1()		throws SQLException	{		String query =			"SELECT DISTINCT " +				"nt.subj, t1.obj, nt.obj " +			"FROM " + NEW_TRIPLES_TABLE + " nt " +			"LEFT JOIN " + TRIPLES_TABLE + " t1 ON " +			"   nt.pred = t1.subj AND " +			"   t1.pred = " + _repository.rdfsSubPropertyOfId + " " +			"LEFT JOIN " + RESOURCES_TABLE + " r ON " +			"   r.id = t1.obj " +			"LEFT JOIN " + TRIPLES_TABLE + " t2 ON " +			"   nt.subj = t2.subj AND " +

⌨️ 快捷键说明

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