pla*_*and 1 regex sparql dbpedia
我正在尝试使用dbpedia和sparql创建特定行业类型(PaaS/SaaS)中的公司列表.我读了这篇关于创建具有一定数量员工的公司列表的帖子,我想在sparql查询中为特定行业过滤,例如:
https://gist.github.com/szydan/e801fa687587d9eb0f6a
我试过这个查询(在这里省略前缀):
CONSTRUCT{
?iri a dbpedia-owl:Company;
foaf:name ?companyName;
dbpedia-owl:abstract ?description;
owl:sameAs ?sameAs;
dbpedia:countryCode ?countryCode;
sindicetech:locationName ?locationName;
sindicetech:locationCityName ?locationCityName
}WHERE{
?iri a dbpedia-owl:Company.
OPTIONAL{
?iri dbpedia-owl:abstract ?description.
FILTER( lang(?description) = "en")
FILTER (regex(?description, '^platform$')) .
}
{
OPTIONAL{
?iri foaf:name ?companyName.
FILTER( lang(?companyName) = "en")
}
}UNION{
OPTIONAL{
?iri rdfs:label ?companyName .
FILTER( lang(?companyName) = "en")
}
}
OPTIONAL{
?iri owl:sameAs ?sameAs
}
{
OPTIONAL{
?iri dbpedia:locationCountry ?country.
?country dbpedia:countryCode ?countryCode
FILTER( lang(?countryCode) = "en")
}
}UNION{
OPTIONAL{
?iri dbpedia-owl:locationCountry ?country.
?country dbpedia:countryCode ?countryCode
FILTER( lang(?countryCode) = "en")
}
}
OPTIONAL{
?iri dbpedia-owl:location ?location.
?location dbpedia:name ?locationName
FILTER( lang(?locationName) = "en")
}
OPTIONAL{
?iri dbpedia-owl:locationCity ?locationCity.
?locationCity rdfs:label ?locationCityName
FILTER( lang(?locationCityName) = "en")
}
}
LIMIT 100
Run Code Online (Sandbox Code Playgroud)
看看我是否能找到平台作为服务公司...但我得到了各种结果,在描述中没有这个词.也许FILTER (regex(?description, '^platform$'))正则表达式是错的?有没有办法可以过滤:
?industrySector dbpedia-owl:industry <http://dbpedia.org/resource/Platform_as_a_service>
或许我应该尝试通过过滤本体论来缩小范围?
http://mappings.dbpedia.org/index.php/OntologyProperty:Industry
我正在使用DBPEDIA的Virtuoso来测试这些查询,理想情况下,我想通过CONSTRUCT查询到达RDF类别层次结构,这样我就可以获得特定行业中的所有公司,例如PaaS,SaaS等.但是我没有和CONSTRUCT查询结婚,我会接受任何建议!
首先,两个笔记.
{
OPTIONAL{
?iri foaf:name ?companyName.
FILTER( lang(?companyName) = "en")
}
}UNION{
OPTIONAL{
?iri rdfs:label ?companyName .
FILTER( lang(?companyName) = "en")
}
}
Run Code Online (Sandbox Code Playgroud)
或
optional {
?iri rdfs:label|foaf:name ?companyName .
filter langMatches(lang(?companyName),"en")
}
Run Code Online (Sandbox Code Playgroud)
要么
values ?nameProperty { rdfs:label foaf:name }
optional {
?iri ?nameProperty ?companyName .
filter langMatches(lang(?companyName),"en")
}
Run Code Online (Sandbox Code Playgroud)
属性路径也可以缩短查询的其他部分.例如,
?iri dbpedia-owl:locationCity ?locationCity.
?locationCity rdfs:label ?locationCityName
Run Code Online (Sandbox Code Playgroud)
可以只是:
?iri dbpedia-owl:locationCity/rdfs:label ?locationCityName
Run Code Online (Sandbox Code Playgroud)
因为你没有在任何地方使用?locationCity.
最后,至于
我得到的各种结果在描述中没有这个词.也许FILTER(正则表达式(?description,'^ platform $'))正则表达式是错误的?
正则表达式并不完全符合您的要求:
FILTER (regex(?description, '^platform$'))
Run Code Online (Sandbox Code Playgroud)
只有在字符串中的字符完全是"平台"时才会匹配.看起来你更想要检查描述是否包含单词platform,在这种情况下你可以使用contains,如contains(?description,"platform").但即使你这样更新,你也会有
optional {
?iri dbpedia-owl:abstract ?description.
filter contains(?description,"platform")
filter langMatches(lang(?description),"en")
}
Run Code Online (Sandbox Code Playgroud)
那仍然在一个可选区块内.可选的整点是,即使可选部分不匹配,您也可以获得结果.如果您想要求包含单词platform的说明,请不要将其设为可选.
毕竟,您的查询变为:
prefix sindicetech: <urn:ex:sindicetech:>
construct {
?iri a dbpedia-owl:Company ;
foaf:name ?companyName ;
dbpedia-owl:abstract ?description ;
owl:sameAs ?sameAs ;
dbpedia:countryCode ?countryCode ;
sindicetech:locationName ?locationName ;
sindicetech:locationCityName ?locationCityName
}
where {
?iri a dbpedia-owl:Company ;
dbpedia-owl:abstract ?description .
filter langMatches(lang(?description),"en") .
filter contains(?description,"platform") .
optional {
?iri foaf:name|rdfs:label ?companyName.
filter langMatches(lang(?companyName),"en")
}
optional {
?iri owl:sameAs ?sameAs
}
optional {
?iri (dbpedia:locationCountry|dbpedia-owl:locationCountry)/dbpedia:countryCode ?countryCode .
filter langMatches(lang(?countryCode),"en")
}
optional {
?iri dbpedia-owl:location/dbpedia:name ?locationName
filter langMatches(lang(?locationName),"en")
}
optional {
?iri dbpedia-owl:locationCity/rdfs:label ?locationCityName
filter langMatches(lang(?locationCityName),"en")
}
}
limit 100
Run Code Online (Sandbox Code Playgroud)
您可以看到结果是关于在其描述中具有"平台"的公司.
请注意,它们都没有任何dbpedia:countryCode属性.我不知道你在哪里找到了这个属性,但它似乎没有在DBpedia的任何地方使用过.查询select(count(*)as?n){?x dbpedia:countryCode?y}返回0.
有没有办法可以过滤:
Run Code Online (Sandbox Code Playgroud)?industrySector dbpedia-owl:industry <http://dbpedia.org/resource/Platform_as_a_service>
如果你看看http://dbpedia.org/resource/Platform_as_a_service,你会发现它与许多公司有关(但并非所有公司都是如此):

您可能只是要求任何与任何财产相关的公司.例如,
select distinct ?company where {
?company a dbpedia-owl:Company ;
?property dbpedia:Platform_as_a_service .
}
Run Code Online (Sandbox Code Playgroud)
您也可以使用该方法来构建更详细的信息.我最终得到这样的东西:
prefix sindicetech: <urn:ex:sindicetech:>
construct {
?company a dbpedia-owl:Company ;
foaf:name ?label ;
dbpedia-owl:abstract ?abstract ;
owl:sameAs ?_company ;
sindicetech:location [ sindicetech:city ?city ;
sindicetech:country ?country ] .
}
where {
?company a dbpedia-owl:Company ;
?property dbpedia:Platform_as_a_service ;
rdfs:label ?label ;
dbpedia-owl:abstract ?abstract .
filter langMatches(lang(?label),"en")
filter langMatches(lang(?abstract),"en")
optional {
?company owl:sameAs ?_company
}
optional {
?company dbpedia-owl:location [ rdfs:label ?city ;
dbpedia-owl:country/rdfs:label ?country ] .
filter langMatches(lang(?city),"en")
filter langMatches(lang(?country),"en")
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
542 次 |
| 最近记录: |