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/
时间: 2024-10-09 00:12:42

Regular Expression "not matching" and SPARQL Filter function usage的相关文章

LeetCode 10. Regular Expression Matching

https://leetcode.com/problems/regular-expression-matching/description/ Implement regular expression matching with support for '.' and '*'. '.' Matches any single character. '*' Matches zero or more of the preceding element. The matching should cover

Java [leetcode 10] Regular Expression Matching

问题描述: Implement regular expression matching with support for '.' and '*'. '.' Matches any single character. '*' Matches zero or more of the preceding element. http://i.cnblogs.com/EditPosts.aspx?opt=1 The matching should cover the entire input string

【leetcode】Regular Expression Matching (hard) ★

Implement regular expression matching with support for '.' and '*'. '.' Matches any single character. '*' Matches zero or more of the preceding element. The matching should cover the entire input string (not partial). The function prototype should be

[LeetCode] Regular Expression Matching(递归)

Implement regular expression matching with support for '.' and '*'. '.' Matches any single character. '*' Matches zero or more of the preceding element. The matching should cover the entire input string (not partial). The function prototype should be

[LeetCode] 10. Regular Expression Matching ☆☆☆☆☆

Implement regular expression matching with support for '.' and '*'. '.' Matches any single character. '*' Matches zero or more of the preceding element. The matching should cover the entire input string (not partial). The function prototype should be

LeetCode10 Regular Expression Matching

题意: Implement regular expression matching with support for '.' and '*'. '.' Matches any single character. '*' Matches zero or more of the preceding element. The matching should cover the entire input string (not partial). The function prototype shoul

Regular Expression Matching

Implement regular expression matching with support for '.' and '*'. '.' Matches any single character. '*' Matches zero or more of the preceding element. The matching should cover the entire input string (not partial). The function prototype should be

Java for LeetCode 010 Regular Expression Matching

Implement regular expression matching with support for '.' and '*'. '.' Matches any single character. '*' Matches zero or more of the preceding element. The matching should cover the entire input string (not partial). The function prototype should be

[LeetCode][Python]Regular Expression Matching

# -*- coding: utf8 -*-'''https://oj.leetcode.com/problems/regular-expression-matching/ Implement regular expression matching with support for '.' and '*'. '.' Matches any single character.'*' Matches zero or more of the preceding element. The matchin