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

📄 rdfschemarepository.java

📁 这是外国一个开源推理机
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
	public StatementIterator getClasses() {		return _queryOneColumnTable(CLASS_TABLE, "id", URIImpl.RDF_TYPE, URIImpl.RDFS_CLASS);	}	public boolean isClass(Resource resource) {		return _isRowInOneColumnTable(CLASS_TABLE, "id", resource);	}	public StatementIterator getProperties() {		return _queryOneColumnTable(PROPERTY_TABLE, "id", URIImpl.RDF_TYPE, URIImpl.RDF_PROPERTY);	}	public boolean isProperty(Resource resource) {		return _isRowInOneColumnTable(PROPERTY_TABLE, "id", resource);	}	public StatementIterator getSubClassOf(Resource subClass, Resource superClass) {		return _queryTwoColumnTable(				SUBCLASSOF_TABLE, "sub", "super",				subClass, URIImpl.RDFS_SUBCLASSOF, superClass);	}	public StatementIterator getDirectSubClassOf(Resource subClass, Resource superClass) {		return _queryTwoColumnTable(				DIRECT_SUBCLASSOF_TABLE, "sub", "super",				subClass, URIImpl.RDFS_SUBCLASSOF, superClass);	}	public boolean isSubClassOf(Resource subClass, Resource superClass) {		return _isRowInTwoColumnTable(				SUBCLASSOF_TABLE, "sub", "super",				subClass, superClass);	}	public boolean isDirectSubClassOf(Resource subClass, Resource superClass) {		return _isRowInTwoColumnTable(				DIRECT_SUBCLASSOF_TABLE, "sub", "super",				subClass, superClass);	}	public StatementIterator getSubPropertyOf(Resource subProperty, Resource superProperty) {		return _queryTwoColumnTable(				SUBPROPERTYOF_TABLE, "sub", "super",				subProperty, URIImpl.RDFS_SUBPROPERTYOF, superProperty);	}	public StatementIterator getDirectSubPropertyOf(Resource subProperty, Resource superProperty) {		return _queryTwoColumnTable(				DIRECT_SUBPROPERTYOF_TABLE, "sub", "super",				subProperty, URIImpl.RDFS_SUBPROPERTYOF, superProperty);	}	public boolean isSubPropertyOf(Resource subProperty, Resource superProperty) {		return _isRowInTwoColumnTable(				SUBPROPERTYOF_TABLE, "sub", "super",				subProperty, superProperty);	}	public boolean isDirectSubPropertyOf(Resource subProperty, Resource superProperty) {		return _isRowInTwoColumnTable(				DIRECT_SUBPROPERTYOF_TABLE, "sub", "super",				subProperty, superProperty);	}	public StatementIterator getDomain(Resource prop, Resource domain) {		return _queryTwoColumnTable(				DOMAIN_TABLE, "property", "class",				prop, URIImpl.RDFS_DOMAIN, domain);	}	public StatementIterator getRange(Resource prop, Resource domain) {		return _queryTwoColumnTable(				RANGE_TABLE, "property", "class",				prop, URIImpl.RDFS_DOMAIN, domain);	}	public StatementIterator getType(Resource anInstance, Resource aClass) {		return _queryTwoColumnTable(				INSTANCEOF_TABLE, "inst", "class",				anInstance, URIImpl.RDF_TYPE, aClass);	}	public StatementIterator getDirectType(Resource anInstance, Resource aClass) {		return _queryTwoColumnTable(				PROPER_INSTANCEOF_TABLE, "inst", "class",				anInstance, URIImpl.RDF_TYPE, aClass);	}	public boolean isType(Resource anInstance, Resource aClass) {		return _isRowInTwoColumnTable(				INSTANCEOF_TABLE, "inst", "class",				anInstance, aClass);	}	public boolean isDirectType(Resource anInstance, Resource aClass) {		return _isRowInTwoColumnTable(				PROPER_INSTANCEOF_TABLE, "inst", "class",				anInstance, aClass);	}	public LiteralIterator getLiterals(String label, String language, URI datatype) {		int datatypeId = 0;		if (datatype != null) {			datatypeId = _getURIId(datatype);			if (datatypeId == 0) {				// datatype URI not found				return new EmptyLiteralIterator();			}		}		String query =				"SELECT l.id, dt.id, dt.namespace, dt.localname, l.language, l.label " +				"FROM " + LITERALS_TABLE + " l, " + RESOURCES_TABLE + " dt " +				"WHERE l.datatype = dt.id";		boolean firstPartWritten = false;		// label		if (label != null) {			// labelHash			long labelHash = _getLabelHash(label);			query += " l.labelHash = " + labelHash;			// label			query += " AND l.label ";			if (_rdbms.emptyStringIsNull() && label.length() == 0) {				query += "IS NULL";			}			else {				query += "= '" + _rdbms.escapeString(label) + "'";			}			firstPartWritten = true;		}		//  language		if (language != null && datatype == null) {			if (firstPartWritten) {				query += " AND";			}			query += " l.language = '" + _rdbms.escapeString(language) + "'";			firstPartWritten = true;		}		// datatype		if (datatype != null) {			if (firstPartWritten) {				query += " AND";			}			query += "dt.id = " + datatypeId;		}		try {			Connection con = _rdbms.getConnection();			return new RdbmsLiteralIterator(this, _namespaceNames, con, query);		}		catch (SQLException e) {			throw new SailInternalException(e);		}	}	/**	 * Queries a one-column table like <tt>CLASS_TABLE</tt> or <tt>PROPER_INSTANCEOF_TABLE</tt>.	 *	 * @param tableName The name of the table to query.	 * @param colName The name of the column in the table.	 * @param prop The property that should be returned by the resulting StatementIterator.	 * @param obj The object that should be returned by the resulting StatementIterator.	 * @return A StatementIterator containing the requested statements.	 **/	protected StatementIterator _queryOneColumnTable(String tableName, String colName, URI prop, Resource obj) {		String query =				"SELECT r.id, r.namespace, r.localname FROM " +					tableName + " t, " + 					RESOURCES_TABLE + " r " +				"WHERE t."+colName + " = r.id";		try {			Connection con = _rdbms.getConnection();			return new RdbmsStatementIterator(					this, _namespaceNames, con,					query, null, null, prop, obj);		}		catch (SQLException e) {			throw new SailInternalException(e);		}	}	/**	 * Checks whether a resource is present in a one-column table like	 * <tt>CLASS_TABLE</tt> or <tt>PROPERTY_TABLE</tt>.	 *	 * @param tableName The name of the table to query.	 * @param colName The name of the column in the table.	 * @param val The value that the column should have.	 **/	protected boolean _isRowInOneColumnTable(String tableName, String colName, Resource val) {		int id = _getResourceId(val);		if (id == 0) {			// unknown resource			return false;		}		String query =				"SELECT * FROM " + tableName +				" WHERE " + colName + " = " + id;		try {			return _rdbms.queryHasResults(query);		}		catch (SQLException e) {			throw new SailInternalException(e);		}	}	/**	 * Queries a two-column table like	 * <tt>SUBCLASSOF_TABLE</tt>, <tt>DIRECT_SUBCLASSOF_TABLE</tt>,	 * <tt>SUBPROPERTYOF_TABLE</tt>, <tt>DIRECT_SUBPROPERTYOF_TABLE</tt>,	 * <tt>INSTANCEOF_TABLE</tt>, <tt>PROPER_INSTANCEOF_TABLE</tt>,	 * <tt>DOMAIN_TABLE</tt> or <tt>RANGE_TABLE</tt>.	 *	 * @param tableName The name of the table to query.	 * @param col1Name The name of the first column in the table.	 * @param col2Name The name of the second column in the table.	 * @param val1 The value that the first column should have, or	 * <tt>null</tt> for a wildcard.	 * @param prop The property that should be returned by the	 * resulting StatementIterator.	 * @param val2 The value that the second column should have, or	 * <tt>null</tt> for a wildcard.	 * @return A StatementIterator containing the requested statements.	 **/	protected StatementIterator _queryTwoColumnTable(			String tableName, String col1Name, String col2Name,			Resource val1, URI prop, Resource val2)	{		int id1 = 0, id2 = 0;		if (val1 != null) {			id1 = _getResourceId(val1);			if (id1 == 0) {				// unknown resource				return new EmptyStatementIterator();			}		}		if (val2 != null) {			id2 = _getResourceId(val2);			if (id2 == 0) {				// unknown resource				return new EmptyStatementIterator();			}		}		String select = "SELECT ";		String from = " FROM " + tableName + " t";		String where = " WHERE ";		// val1		if (id1 != 0) {			// val1 is specified			where += "t."+col1Name + " = " + id1;		}		else {			// val1 is a wildcard			select += "r1.id, r1.namespace, r1.localname";			from += ", " + RESOURCES_TABLE + " r1";			where += "t."+col1Name + " = r1.id";		}		// val2		if (id2 != 0) {			// val2 is specified			where += " AND t."+col2Name + " = " + id2;		}		else {			// val2 is a wildcard			if (id1 == 0) {				select += ", ";			}			select += "r2.id, r2.namespace, r2.localname";			from += ", " + RESOURCES_TABLE + " r2";			where += " AND t."+col2Name + " = r2.id";		}		if (id1 != 0 && id2 != 0) {			select += "*";		}		String query = select + from + where;		try {			Connection con = _rdbms.getConnection();			return new RdbmsStatementIterator(					this, _namespaceNames, con,					query, null, val1, prop, val2);		}		catch (SQLException e) {			throw new SailInternalException(e);		}	}	/**	 * Checks whether a combination of two resources is present in	 * a two-column table like	 * <tt>SUBCLASSOF_TABLE</tt>, <tt>DIRECT_SUBCLASSOF_TABLE</tt>,	 * <tt>SUBPROPERTYOF_TABLE</tt>, <tt>DIRECT_SUBPROPERTYOF_TABLE</tt>,	 * <tt>INSTANCEOF_TABLE</tt>, <tt>PROPER_INSTANCEOF_TABLE</tt>,	 * <tt>DOMAIN_TABLE</tt> or <tt>RANGE_TABLE</tt>	 *	 * @param tableName The name of the table to query.	 * @param col1Name The name of the first column in the table.	 * @param col2Name The name of the second column in the table.	 * @param val1 The value that the first column should have.	 * @param val2 The value that the second column should have.	 **/	protected boolean _isRowInTwoColumnTable(			String tableName, String col1Name, String col2Name,			Resource val1, Resource val2)	{		int id1 = _getResourceId(val1);		if (id1 == 0) {			return false;		}		int id2 = _getResourceId(val2);		if (id2 == 0) {			return false;		}		String query = 				"SELECT * FROM " + tableName +				" WHERE " + col1Name + " = " + id1 +				" AND " + col2Name + " = " + id2;		try {			return _rdbms.queryHasResults(query);		}		catch (SQLException e) {			throw new SailInternalException(e);		}	}	// Overrides RdfSource._convertPathExpressionToSQL(...)	protected PathExpression _convertPathExpressionToSQL(			PathExpression pathExpr, String peId,			StringBuffer from, StringBuffer where, Map varToSqlIdMapping)	{		if (pathExpr instanceof DirectType) {			DirectType dt = (DirectType)pathExpr;			from.append(", " + PROPER_INSTANCEOF_TABLE + " " + peId);			_processPathExpressionVar(dt.getSubjectVar(), peId+".inst", where, varToSqlIdMapping);			_processPathExpressionVar(dt.getObjectVar(), peId+".class", where, varToSqlIdMapping);			return null;		}		else if (pathExpr instanceof DirectSubClassOf) {			DirectSubClassOf dsco = (DirectSubClassOf)pathExpr;			from.append(", " + DIRECT_SUBCLASSOF_TABLE + " " + peId);			_processPathExpressionVar(dsco.getSubjectVar(), peId+".sub", where, varToSqlIdMapping);			_processPathExpressionVar(dsco.getObjectVar(), peId+".super", where, varToSqlIdMapping);			return null;		}		else if (pathExpr instanceof DirectSubPropertyOf) {			DirectSubPropertyOf dspo = (DirectSubPropertyOf)pathExpr;			from.append(", " + DIRECT_SUBPROPERTYOF_TABLE + " " + peId);			_processPathExpressionVar(dspo.getSubjectVar(), peId+".sub", where, varToSqlIdMapping);			_processPathExpressionVar(dspo.getObjectVar(), peId+".super", where, varToSqlIdMapping);			return null;		}		else {			if (pathExpr instanceof TriplePattern) {				TriplePattern tp = (TriplePattern)pathExpr;				Value predicate = tp.getPredicateVar().getValue();				if (URIImpl.RDF_TYPE.equals(predicate)) {					// Use INSTANCEOF_TABLE					from.append(", " + INSTANCEOF_TABLE + " " + peId);					_processPathExpressionVar(tp.getSubjectVar(), peId+".inst", where, varToSqlIdMapping);					_processPathExpressionVar(tp.getObjectVar(), peId+".class", where, varToSqlIdMapping);					return null;				}				else if (URIImpl.RDFS_SUBCLASSOF.equals(predicate)) {					// Use SUBCLASSOF_TABLE					from.append(", " + SUBCLASSOF_TABLE + " " + peId);					_processPathExpressionVar(tp.getSubjectVar(), peId+".sub", where, varToSqlIdMapping);					_processPathExpressionVar(tp.getObjectVar(), peId+".super", where, varToSqlIdMapping);					return null;				}				else if (URIImpl.RDFS_SUBPROPERTYOF.equals(predicate)) {					// Use SUBPROPERTYOF_TABLE					from.append(", " + SUBPROPERTYOF_TABLE + " " + peId);					_processPathExpressionVar(tp.getSubjectVar(), peId+".sub", where, varToSqlIdMapping);					_processPathExpressionVar(tp.getObjectVar(), peId+".super", where, varToSqlIdMapping);					return null;				}			}			return super._convertPathExpressionToSQL(pathExpr, peId, from, where, varToSqlIdMapping);		}	}	public RDBMS getRDBMS() {		return _rdbms;	}}

⌨️ 快捷键说明

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