您尚未显示您的数据,因此我无法使用您的确切查询或数据,但根据您的评论,听起来您正在获取 IRI(例如,http://www.semanticweb.org/raya/ontologies/test6#Good-behaviour
)作为结果,而您只需要 string Good-behaviour
。你可以用它strafter
来做到这一点。例如,如果您有这样的数据:
@prefix : <http://stackoverflow.com/questions/20830056/> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
:retrieving-the-class-name-of-a-specific-subclass-in-owl
rdfs:label "retrieving the class name of a specific subclass in owl"@en .
然后像这样的查询将返回具有完整 IRI 的结果:
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
select ?question where {
?question rdfs:label ?label .
}
---------------------------------------------------------------------------------------------------------
| question |
=========================================================================================================
| <http://stackoverflow.com/questions/20830056/retrieving-the-class-name-of-a-specific-subclass-in-owl> |
---------------------------------------------------------------------------------------------------------
您可以使用strafter
在其他字符串之后获取字符串的一部分。例如,
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
select ?q where {
?question rdfs:label ?label .
bind(strafter(str(?question),"http://stackoverflow.com/questions/20830056/") as ?q)
}
-------------------------------------------------------------
| q |
=============================================================
| "retrieving-the-class-name-of-a-specific-subclass-in-owl" |
-------------------------------------------------------------
如果您在查询中定义前缀,例如,作为 a so:
,那么您也可以使用str(so:)
代替字符串形式。如果您愿意,您还可以在变量列表中而不是图形模式中进行字符串操作。看起来像这样:
prefix so: <http://stackoverflow.com/questions/20830056/>
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
select (strafter(str(?question),str(so:)) as ?q) where {
?question rdfs:label ?label .
}
-------------------------------------------------------------
| q |
=============================================================
| "retrieving-the-class-name-of-a-specific-subclass-in-owl" |
-------------------------------------------------------------