选择DBpedia资源中摘要中至少出现N个字词吗?

编程入门 行业动态 更新时间:2024-10-25 06:25:22
本文介绍了选择DBpedia资源中摘要中至少出现N个字词吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有这个要求,导致产生了一些DBpedia资源及其摘要。我该如何过滤结果以仅获取摘要中至少包含一定数量的特定单词出现的资源?

PREFIX rdf:< http://www.w3/1999/02/22-rdf-syntax-ns#> PREFIX dbpedia-owl:< http://www.dbpedial/> PREFIX rdfs:< http://www.w3/2000/01/rdf-schema#> PREFIX泡沫:< http://xmlns/foaf/0.1/> 选择不同的?resource?url?resume,其中{?resource rdfs:label?Nom。 ?resource foaf:isPrimaryTopicOf?url。 资源dbo:抽象简历。 FILTER langMatches(lang(?Nom), EN) FILTER langMatches(lang(?resume), EN)?Nom< bif:contains> 苹果。 }

这是没有绑定功能的新请求:

选择(strlen(replace(replace(Lcase(?resume),'Jobs','_'),'[^ _]','') )as?nbr)?resource?url 其中{?resource rdfs:label?Nom。 ?resource foaf:isPrimaryTopicOf?url。 资源dbo:抽象简历。 FILTER langMatches(lang(?Nom), EN) FILTER langMatches(lang(?resume), EN)?Nom< bif:contains> Apple。} GROUP BY?Nom 具有(?nbr> = 1)

解决方案

这不是绝对完美,但对于您要完成的工作,它应该相对较好。您可以使用替换将您要计数的单词的所有实例替换为单个字符(例如 _)。然后,您可以再次使用 replace 将该字符除 以外的所有内容替换为空字符串。然后,您将得到一个类似于 ______的字符串,其中长度是单词在字符串中出现的次数。例如,这是一个查询,该查询在摘要中对 the进行计数,仅保留那些至少出现 the五次的查询。

< { values?x {dbr:Horse dbr:Cat dbr:Dog} ?x dbo: select?x?n抽象?abs 过滤器langMatches(lang(?abs),'en') bind(strlen(replace(replace(?abs,'\\thes's','_ '),'[[^ _]',''))as?nThe)过滤器(?nThe> = 5)}

SPARQL结果

I have this request that results some DBpedia resources and their abstracts. How can I filter the results to get just the resources whose abstracts contain at least a certain number of occurrences of a particular word?

PREFIX rdf:<www.w3/1999/02/22-rdf-syntax-ns#> PREFIX dbpedia-owl:<www.dbpedial/> PREFIX rdfs: <www.w3/2000/01/rdf-schema#> PREFIX foaf: <xmlns/foaf/0.1/> select distinct ?resource ?url ?resume where { ?resource rdfs:label ?Nom. ?resource foaf:isPrimaryTopicOf ?url. ?resource dbo:abstract ?resume. FILTER langMatches( lang(?Nom), "EN" ) FILTER langMatches( lang(?resume), "EN" ) ?Nom <bif:contains> "apple". }

This is the new request without Bind function:

select (strlen(replace(replace(Lcase(?resume), 'Jobs', '_'),'[^_]', '')) as ?nbr ) ?resource ?url where { ?resource rdfs:label ?Nom. ?resource foaf:isPrimaryTopicOf ?url. ?resource dbo:abstract ?resume. FILTER langMatches( lang(?Nom), "EN" ) FILTER langMatches( lang(?resume), "EN" ) ?Nom <bif:contains> "Apple".} GROUP BY ?Nom Having(?nbr >= 1)

解决方案

This won't be absolutely perfect, but it should work relatively well for what you're trying to accomplish. You can use replace to replace all the instances of the word you want to count with some single character (e.g., '_'). Then you can use replace again to replace everything except that character with the empty string. Then, you have a string like '______', where the length is the number of times that the word appeared in the string. For instance, here's a query that counts 'the' in the abstract, and keeps only those where 'the' appears at least five times.

select ?x ?nThe { values ?x { dbr:Horse dbr:Cat dbr:Dog } ?x dbo:abstract ?abs filter langMatches(lang(?abs),'en') bind(strlen(replace(replace(?abs, '\\sthe\\s', '_'),'[^_]', '')) as ?nThe) filter (?nThe >= 5) }

SPARQL results

更多推荐

选择DBpedia资源中摘要中至少出现N个字词吗?

本文发布于:2023-11-30 04:02:37,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1648650.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字词   摘要   资源   DBpedia

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!