Wikidata+SPARQL:根据股票代码查找公司

Wikidata+SPARQL: lookup a company based on it's ticker symbol

我正在尝试使用 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 的股票代码为 'inside' P414 属性(证券交易所)。

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

我如何扩展此列表以包含代码为 P414 和 P249 的公司 "inside"?

以下是我如何显示不包括 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').
}

所以基于 AKSW and Stanislav 的评论的答案是,这个查询将列出纽约证券交易所的所有股票(只要股票代码被列出 'under' 交易所:

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').
}

并且此查询将在任何证券交易所找到特定股票,或直接引用(此处显示两个不同的股票代码以说明搜索)。这个查询很长,因为维基数据有时在股票代码下有证券交易所子字段,有时则相反。哦,有时它们完全是两个不同的领域(没有联系)。哦,快乐。

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". }
}