package de.fuberlin.wiwiss.d2rq.optimizer.expr;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Stack;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import com.hp.hpl.jena.datatypes.RDFDatatype;
import com.hp.hpl.jena.datatypes.xsd.XSDDatatype;
import com.hp.hpl.jena.graph.Node;
import com.hp.hpl.jena.sparql.core.Var;
import com.hp.hpl.jena.sparql.expr.E_Add;
import com.hp.hpl.jena.sparql.expr.E_Datatype;
import com.hp.hpl.jena.sparql.expr.E_Divide;
import com.hp.hpl.jena.sparql.expr.E_Equals;
import com.hp.hpl.jena.sparql.expr.E_GreaterThan;
import com.hp.hpl.jena.sparql.expr.E_GreaterThanOrEqual;
import com.hp.hpl.jena.sparql.expr.E_IsBlank;
import com.hp.hpl.jena.sparql.expr.E_IsIRI;
import com.hp.hpl.jena.sparql.expr.E_IsLiteral;
import com.hp.hpl.jena.sparql.expr.E_Lang;
import com.hp.hpl.jena.sparql.expr.E_LangMatches;
import com.hp.hpl.jena.sparql.expr.E_LessThan;
import com.hp.hpl.jena.sparql.expr.E_LessThanOrEqual;
import com.hp.hpl.jena.sparql.expr.E_LogicalNot;
import com.hp.hpl.jena.sparql.expr.E_LogicalOr;
import com.hp.hpl.jena.sparql.expr.E_Multiply;
import com.hp.hpl.jena.sparql.expr.E_NotEquals;
import com.hp.hpl.jena.sparql.expr.E_SameTerm;
import com.hp.hpl.jena.sparql.expr.E_Str;
import com.hp.hpl.jena.sparql.expr.E_Subtract;
import com.hp.hpl.jena.sparql.expr.E_UnaryMinus;
import com.hp.hpl.jena.sparql.expr.E_UnaryPlus;
import com.hp.hpl.jena.sparql.expr.Expr;
import com.hp.hpl.jena.sparql.expr.ExprAggregator;
import com.hp.hpl.jena.sparql.expr.ExprEvalException;
import com.hp.hpl.jena.sparql.expr.ExprFunction;
import com.hp.hpl.jena.sparql.expr.ExprFunction0;
import com.hp.hpl.jena.sparql.expr.ExprFunction1;
import com.hp.hpl.jena.sparql.expr.ExprFunction2;
import com.hp.hpl.jena.sparql.expr.ExprFunction3;
import com.hp.hpl.jena.sparql.expr.ExprFunctionN;
import com.hp.hpl.jena.sparql.expr.ExprFunctionOp;
import com.hp.hpl.jena.sparql.expr.ExprVar;
import com.hp.hpl.jena.sparql.expr.ExprVisitor;
import com.hp.hpl.jena.sparql.expr.NodeValue;
import com.hp.hpl.jena.sparql.expr.nodevalue.NodeFunctions;
import com.hp.hpl.jena.sparql.expr.nodevalue.NodeValueBoolean;
import de.fuberlin.wiwiss.d2rq.algebra.Attribute;
import de.fuberlin.wiwiss.d2rq.algebra.ExpressionProjectionSpec;
import de.fuberlin.wiwiss.d2rq.algebra.NodeRelation;
import de.fuberlin.wiwiss.d2rq.algebra.ProjectionSpec;
import de.fuberlin.wiwiss.d2rq.algebra.RelationalOperators;
import de.fuberlin.wiwiss.d2rq.expr.Add;
import de.fuberlin.wiwiss.d2rq.expr.Constant;
import de.fuberlin.wiwiss.d2rq.expr.Divide;
import de.fuberlin.wiwiss.d2rq.expr.Equality;
import de.fuberlin.wiwiss.d2rq.expr.Expression;
import de.fuberlin.wiwiss.d2rq.expr.GreaterThan;
import de.fuberlin.wiwiss.d2rq.expr.GreaterThanOrEqual;
import de.fuberlin.wiwiss.d2rq.expr.LessThan;
import de.fuberlin.wiwiss.d2rq.expr.LessThanOrEqual;
import de.fuberlin.wiwiss.d2rq.expr.Multiply;
import de.fuberlin.wiwiss.d2rq.expr.Negation;
import de.fuberlin.wiwiss.d2rq.expr.SQLExpression;
import de.fuberlin.wiwiss.d2rq.expr.Subtract;
import de.fuberlin.wiwiss.d2rq.expr.UnaryMinus;
import de.fuberlin.wiwiss.d2rq.nodes.DetermineNodeType;
import de.fuberlin.wiwiss.d2rq.nodes.FixedNodeMaker;
import de.fuberlin.wiwiss.d2rq.nodes.NodeMaker;
import de.fuberlin.wiwiss.d2rq.nodes.NodeSetConstraintBuilder;
import de.fuberlin.wiwiss.d2rq.nodes.TypedNodeMaker;
import de.fuberlin.wiwiss.d2rq.values.ValueMaker;
/**
* Attempts to transform a SPARQL FILTER Expr to a SQL Expression
*
* Notes:
* <ul>
* <li>Literals using d2rq:pattern cannot be compared.</li>
* <li>No XSD type checking/conversion or constructor functions yet.</li>
* </ul>
*
* @author Herwig Leimer
* @author Giovanni Mels
*/
public final class TransformExprToSQLApplyer implements ExprVisitor {
private static final Log logger = LogFactory.getLog(TransformExprToSQLApplyer.class);
/**
* Converts a SPARQL filter expression to an SQL expression
*
* @param expr The root node of an {@link Expr Expr} tree, contains the SPARQL filter.
* @param nodeRelation The relation supplying the values to apply the filter on.
* @return The root node of an {@link Expression Expression} tree, if conversion was successful, <code>null</code> otherwise.
*/
public static Expression convert(final Expr expr, final NodeRelation nodeRelation) {
TransformExprToSQLApplyer transformer = new TransformExprToSQLApplyer(nodeRelation);
expr.visit(transformer);
return transformer.result();
}
// TODO Expression.FALSE and Expression.TRUE are not constants
private static final Expression CONSTANT_FALSE = new ConstantEx("false", NodeValueBoolean.FALSE.asNode());
private static final Expression CONSTANT_TRUE = new ConstantEx("true", NodeValueBoolean.TRUE.asNode());
private final NodeRelation nodeRelation;
private final Stack<Expression> expression = new Stack<Expression>();
private boolean convertable; // flag if converting was possible
private String reason = null; // reason why converting failed
/**
* Creates an expression transformer.
*
* @param nodeRelation
*/
public TransformExprToSQLApplyer(NodeRelation nodeRelation)
{
this.convertable = true;
this.nodeRelation = nodeRelation;
}
/**
* Returns the sql Expression
*
* @return the transformed sql expression if converting was possible, otherwise null.
*/
public Expression result()
{
if (!convertable) {
logger.debug("filter conversion failed: " + reason);
return null;
}
if (expression.size() != 1)
throw new IllegalStateException("something is seriously wrong");
Expression result = expression.pop();
logger.debug("Resulting filter = " + result);
return result;
}
public void startVisit()
{
logger.debug("transform started");
}
public void finishVisit()
{
logger.debug("transform finished");
}
public void visit(ExprFunction0 func) {
visitExprFunction(func);
}
public void visit(ExprFunction1 function) {
logger.debug("visit ExprFunction " + function);
if (!convertable) {
expression.push(Expression.FALSE); // prevent stack empty exceptions when conversion
return; // fails in the middle of a multi-arg operator conversion
}
convertFunction(function);
}
public void visit(ExprFunction2 function) {
logger.debug("visit ExprFunction " + function);
if (!convertable) {
expression.push(Expression.FALSE); // prevent stack empty exceptions when conversion
return; // fails in the middle of a multi-arg operator conversion
}
convertFunction(function);
}
public void visit(ExprFunction3 func) {
visitExprFunction(func);
}
public void visit(ExprFunctionN func) {
visitExprFunction(func);
}
public void visit(ExprFunctionOp funcOp) {
visitExprFunction(funcOp);
}
public void visit(ExprAggregator eAgg) {
conversionFailed(eAgg);
}
public void visit(ExprVar var)
{
logger.debug("visit ExprVar " + var);
if (!convertable) {
expression.push(Expression.FALSE); // prevent stack empty exceptions when conversion
return; // fails in the middle of a multi-arg operator conversion
}
String varName = var.getVarName();
// if expression contains a blank node, no conversion to sql can be done
if (Var.isBlankNodeVarName(varName)) {
conversionFailed("blank nodes not supported", var);
return;
}
List<Expression> expressions = toExpression(var);
if (expressions.size() == 1) {
expression.push(expressions.get(0));
} else {
// no single sql-column for sparql-var does exist break up conversion
// (the case for Pattern ValueMakers)
conversionFailed("multi column pattern valuemakers not supported", var);
}
}
public void visit(NodeValue value)
{
logger.debug("visit NodeValue " + value);
if (!convertable) {
expression.push(Expression.FALSE); // pr
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
【资源说明】 基于java知识图谱的农业病虫害数据查询系统(附数据爬虫)源码+全部资料(毕业设计).zip基于java知识图谱的农业病虫害数据查询系统(附数据爬虫)源码+全部资料(毕业设计).zip 【备注】 1、该资源内项目代码都经过测试运行成功,功能ok的情况下才上传的,请放心下载使用! 2、本项目适合计算机相关专业(如软件工程、计科、人工智能、通信工程、自动化、电子信息等)的在校学生、老师或者企业员工下载使用,也可作为毕设项目、课程设计、作业、项目初期立项演示等,当然也适合小白学习进阶。 3、如果基础还行,可以在此代码基础上进行修改,以实现其他功能,也可直接用于毕设、课设、作业等。 欢迎下载,沟通交流,互相学习,共同进步!
资源推荐
资源详情
资源评论
收起资源包目录
基于java知识图谱的农业病虫害数据查询系统(附数据爬虫)源码+全部资料(毕业设计).zip (1163个子文件)
d2r-server.bat 459B
generate-mapping.bat 360B
d2r-query.bat 349B
dump-rdf.bat 348B
mvnw.cmd 6KB
layui.css 78KB
layer.css 14KB
common.css 13KB
laydate.css 7KB
styles.css 5KB
style.css 4KB
main.css 3KB
style.css 2KB
style.css 2KB
reset.css 1KB
stylesheet.css 1KB
code.css 1KB
metadata.css 439B
translationtable.csv 17B
d2r-query 428B
d2r-server 536B
iswc.daml 35KB
userLibrary.dtc 56KB
dump-rdf 427B
generate-mapping 435B
fu-logo.gif 6KB
loading-0.gif 6KB
loading-2.gif 2KB
loading-1.gif 701B
rdf_flyer.24.gif 330B
inherit.gif 57B
.gitignore 395B
.htaccess 81B
ISWC.html 116KB
Expression.html 102KB
D2RQ.html 92KB
ModelD2RQ.html 86KB
D2RQException.html 83KB
Attribute.html 77KB
d2rq-language.html 72KB
PushDownOpFilterVisitor.html 69KB
index-19.html 67KB
constant-values.html 60KB
index-20.html 59KB
index-7.html 58KB
index-22.html 58KB
overview-tree.html 57KB
ResourceMap.html 57KB
index-3.html 55KB
index-4.html 53KB
index-18.html 51KB
index-1.html 51KB
SQL92.html 50KB
ProjectionSpec.html 48KB
RelationName.html 46KB
ConnectedDB.html 45KB
SKOS.html 45KB
PropertyBridge.html 44KB
MappingGenerator.html 43KB
AliasMap.html 43KB
ConnectedDB.html 42KB
index-13.html 42KB
ColumnRenamer.html 42KB
index-16.html 42KB
VarCollector.html 41KB
Vendor.html 41KB
index-9.html 41KB
RelationImpl.html 39KB
AutoReloadableDataset.html 37KB
Relation.html 37KB
D2RServer.html 37KB
Database.html 37KB
Pattern.html 36KB
SystemLoader.html 35KB
package-use.html 35KB
TypedNodeMaker.html 35KB
TransformExprToSQLApplyer.html 35KB
NodeMaker.html 34KB
Oracle.html 34KB
Attribute.html 33KB
SQLServer.html 33KB
AliasMap.html 33KB
QueryIterTableSQL.html 33KB
OpUnionTableSQL.html 33KB
DetermineNodeType.html 32KB
Vendor.html 32KB
Mapping.html 32KB
NodeSetConstraintBuilder.html 32KB
Relation.html 32KB
ValueDecorator.html 31KB
TransformOpBGP.html 31KB
ClassMap.html 31KB
GraphD2RQ.html 31KB
OpTableSQL.html 31KB
MySQL.html 30KB
TransformFilterCNF.html 30KB
index-12.html 30KB
TransformFilterCNF.DistributiveLawApplyer.html 29KB
ConfigLoader.html 29KB
TransformFilterCNF.DeMorganLawApplyer.html 29KB
共 1163 条
- 1
- 2
- 3
- 4
- 5
- 6
- 12
资源评论
不走小道
- 粉丝: 3201
- 资源: 5123
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 毕业设计基于Python卷积神经网络CNN的图像分类系统源码+模型+说明文档+全部数据资料.zip
- matlab 基于SVM的手写字体识别源代码+详细教程
- 课程管理平台 JAVA+Vue.js+SpringBoot+MySQL
- 毕业设计 基于Python卷积神经网络CNN的图像分类系统源码+模型+说明文档+全部数据资料.zip
- matlab 基于SVM的图像分割-真彩色图像分割源代码+详细教程
- go-admin框架vue权限字符-全网最透彻讲解
- matlab 基于SVM的信息粒化时序回归预测-上证指数开盘指数变化趋势和变化空间预测源代码+详细教程
- OBS多平台推流支持插件
- matlab 基于SVM的回归预测分析-上证指数开盘指数预测源代码+详细教程
- comfyui的BrushNet电商公司和摄影公司都在用的AI工作流
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功