Regular Expression "not matching" and SPARQL Filter function usage

OK, I had a problem here when converting bio2rdf.org irefindex data into nanopublication using sparql here: 

in a database, if the item you are looking for has multiple types, but you only need one of those types in your converted data, what you can do is to use a sparql filter function with regex

1. the proper sparql filter syntax is as follows: 

select ?s 
where{
  ?s ?p ?o .
  filter ( #your statements here for filter ) #it's brackets () not curly parenthesis {} 
}

2. the proper regex to match those items that you don't want 

^.*?(?<!Resource)$ # the regex 
filter regex(?interaction_type, "^.*?(?<!Resource)$", "i") # how do you use the regex in the filter
^.*?(?<!Resource)$ means that you are finding stuff that not ending with "Resource" - references: http://www.cnblogs.com/wangqiguo/archive/2012/05/08/2486548.html 
2.例子,查找不以com结尾的字符串。
www.sina.com.cn
www.educ.org
www.hao.cc
www.baidu.com
www.123.com正则
^.*?(?<!com)$  匹配前3行结果。如果查找以com结尾的字符串则使用正则 ^.*?(?<=com)$或者 ^.*?com$  
and the syntax of filter can be referred here: http://www.w3.org/TR/rdf-sparql-query/ , you can search "11.4.13 regex" to get there.

online regex tester is also very helpful when debugging your regex: https://regex101.com/

转载于:https://www.cnblogs.com/RuiYan/p/4150978.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值