维基数据+SPARQL:根据公司的股票代码查找公司 [英] Wikidata+SPARQL: lookup a company based on it's ticker symbol

查看:18
本文介绍了维基数据+SPARQL:根据公司的股票代码查找公司的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用SPARQL根据公司的股票代码查找公司。

此查询将列出企业及其股票代码(基本查询)

SELECT DISTINCT ?id ?idLabel ?ticker
WHERE {
    ?id wdt:P31/wdt:P279* wd:Q4830453 .
    ?id wdt:P249 ?ticker .
    ?id rdfs:label ?idLabel 
    FILTER(LANG(?idLabel) = 'en').
}

但是,IBM不包括在内,因为IBM将其股票代码放在P414属性(股票交易所)的"内部"。

https://www.wikidata.org/wiki/Q37156

如何扩展此列表以包括"内部"具有P414和P249股票代码的公司?

下面是我如何显示不包括IBM的方法:

SELECT DISTINCT ?id ?idLabel ?exchange ?ticker2
WHERE {
    ?id wdt:P31/wdt:P279* wd:Q4830453 .
    ?id wdt:P249 ?ticker . FILTER(LCASE(STR(?ticker)) = 'ibm') .
    ?id rdfs:label ?idLabel 
    FILTER(LANG(?idLabel) = 'en').
}

推荐答案

因此,根据AKSWStanislav的评论得到的答案是,此查询将列出纽约证券交易所的所有股票(只要股票代码是在交易所下列出的:

SELECT DISTINCT ?id ?idLabel ?exchange ?ticker
WHERE {
    ?id wdt:P31/wdt:P279* wd:Q4830453 .
    ?id p:P414 ?exchange . 
    ?exchange ps:P414 wd:Q13677 .
    ?exchange pq:P249 ?ticker .

    ?id rdfs:label ?idLabel 
    FILTER(LANG(?idLabel) = 'en').
}

此查询将在纽约证券交易所找到特定的股票(IBM):

SELECT DISTINCT ?id ?idLabel ?exchange ?ticker
WHERE {
    ?id wdt:P31/wdt:P279* wd:Q4830453 .
    ?id p:P414 ?exchange . 
    ?exchange ps:P414 wd:Q13677 .
    ?exchange pq:P249 ?ticker . FILTER(LCASE(STR(?ticker)) = 'ibm') .

    ?id rdfs:label ?idLabel 
    FILTER(LANG(?idLabel) = 'en').
}

此查询将在任何证券交易所查找特定的股票,或者直接引用(此处显示了两个不同的股票代码以说明搜索)。这个查询相当长,因为Wikidata有时在股票代码下面有股票交易子字段,有时在股票代码下面有证券交易子字段。哦,有时它们是完全不同的两个领域(没有联系)。哦,乔伊。

SELECT DISTINCT ?id ?idLabel ?exchange ?exchangeLabel ?ticker
WHERE {
    ?id wdt:P31/wdt:P279* wd:Q4830453 .
    { 
       # Find cases where the ticker is the main attribute, and the exchange may be below it.
       ?id wdt:P249 ?ticker . FILTER(LCASE(STR(?ticker)) = 'nsu') .
       ?id p:P249 ?tickersub .
       ?tickersub pq:P414 ?exchange 
    }
    UNION {
       # Find the exchange and it's ticker 
       ?id wdt:P414 ?exchange . 
       ?id p:P414 ?exchangesub .
       ?exchangesub pq:P249 ?ticker . FILTER(LCASE(STR(?ticker)) = 'ibm') .
    } 
    UNION {
       # Find the exchange and it's ticker 
       ?id wdt:P414 ?exchange . 
       ?id wdt:P249 ?ticker . FILTER(LCASE(STR(?ticker)) = 'frme') .
    } 
    SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}

这篇关于维基数据+SPARQL:根据公司的股票代码查找公司的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆