且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用SPARQL查询与字符串的***匹配?

更新时间:2022-06-06 00:34:09

我修改了评论中提到的正则表达式方法 ,并提出了一个效果很好的解决方案,比我使用bif:contains所能获得的任何优势都要好:

I adapted the regex-approach mentioned in the comments and came up with a solution that works pretty well, better than anything I could get with bif:contains:

   SELECT ?resource ?title ?match strlen(str(?title)) as ?lenTitle strlen(str(?match)) as ?lenMatch

   WHERE {
      ?resource foaf:name ?title .
      ?resource rdf:type schema:Movie .
      ?resource dbo:director ?director .
      bind( replace(LCASE(CONCAT('x',?title)), "^x(die)*(?:.*?(hard))*(?:.*?(with))*.*$", "$1$2$3") as ?match ) 
   }

   ORDER BY DESC(?lenMatch) ASC(?lenTitle)

   LIMIT 5

这并不完美,因此我仍然愿意征求建议。

It's not perfect, so I'm still open for suggestions.