gpt4 book ai didi

python - 将字符串分解为主谓词和宾语的三元组(三个字段的元组)。

转载 作者:塔克拉玛干 更新时间:2023-11-03 05:45:56 27 4
gpt4 key购买 nike

例如:

示例 RDF 字符串。

“In_the_Bedroom”、“The_Patriot_(2000_film)”、“Black_Knight_(film)”、“The_Last_Kiss”、“Cassandras_Dream”; "1948-12-12"; "Tom Wilkinson (Schauspieler)", "טום וילקינסון", "テム・ウイルキンソン", "Tom Wilkinson", "ום וילינסו优ソן", "mu .

给定字符串的三元组 -

<Tom_Wilkinson_(actor)> <actedIn> "In_the_Bedroom"     
<Tom_Wilkinson_(actor)> <actedIn> "The_Patriot_(2000_film)"
<Tom_Wilkinson_(actor)> <actedIn> "Black_Knight_(film)"
<Tom_Wilkinson_(actor)> <actedIn> "The_Last_Kiss"
<Tom_Wilkinson_(actor)> <actedIn> "Cassandras_Dream"
<Tom_Wilkinson_(actor)> <bornOnDate> "1948-12-12"
<Tom_Wilkinson_(actor)> <isCalled> "Tom Wilkinson (Schauspieler)"

注意 - 对象之间可以有空格。例如,“Tom Wilkinson (Schauspieler)”是一个包含空格的对象。

最佳答案

您提供的输入实际上已经是某些 RDF 的 Turtle(或 N3)序列化。它通常会被格式化成这样,并指定一些 @base:

@base <http://stackoverflow.com/q/23192184/1281433> .

<Tom_Wilkinson_(actor)> <actedIn> "In_the_Bedroom" , "The_Patriot_(2000_film)" ,
"Black_Knight_(film)" , "The_Last_Kiss" ,
"Cassandras_Dream";
<bornOnDate> "1948-12-12";
<isCalled> "Tom Wilkinson (Schauspieler)" ,
"טום וילקינסון" , "トム・ウィルキンソン" ,
"Tom Wilkinson" , "ום וילקינסון" ,
"ム・ウィルキンソン" .

如果您添加适当的 @base 声明,那么您可以使用任何可以读取 Turtle 并以 N-Triples 序列化的库来读取输入和写入输出。例如,使用 Jena 的 rdfcat您可以转换为多种不同的格式,包括 N-Triples:

$ rdfcat -out N-TRIPLES input.ttl
<http://stackoverflow.com/q/23192184/Tom_Wilkinson_(actor)> <http://stackoverflow.com/q/23192184/actedIn> "Black_Knight_(film)" .
<http://stackoverflow.com/q/23192184/Tom_Wilkinson_(actor)> <http://stackoverflow.com/q/23192184/isCalled> "ム・ウィルキンソン" .
<http://stackoverflow.com/q/23192184/Tom_Wilkinson_(actor)> <http://stackoverflow.com/q/23192184/isCalled> "トム・ウィルキンソン" .
<http://stackoverflow.com/q/23192184/Tom_Wilkinson_(actor)> <http://stackoverflow.com/q/23192184/isCalled> "Tom Wilkinson (Schauspieler)" .
<http://stackoverflow.com/q/23192184/Tom_Wilkinson_(actor)> <http://stackoverflow.com/q/23192184/isCalled> "ום וילקינסון" .
<http://stackoverflow.com/q/23192184/Tom_Wilkinson_(actor)> <http://stackoverflow.com/q/23192184/isCalled> "טום וילקינסון" .
<http://stackoverflow.com/q/23192184/Tom_Wilkinson_(actor)> <http://stackoverflow.com/q/23192184/actedIn> "The_Last_Kiss" .
<http://stackoverflow.com/q/23192184/Tom_Wilkinson_(actor)> <http://stackoverflow.com/q/23192184/bornOnDate> "1948-12-12" .
<http://stackoverflow.com/q/23192184/Tom_Wilkinson_(actor)> <http://stackoverflow.com/q/23192184/actedIn> "The_Patriot_(2000_film)" .
<http://stackoverflow.com/q/23192184/Tom_Wilkinson_(actor)> <http://stackoverflow.com/q/23192184/actedIn> "In_the_Bedroom" .
<http://stackoverflow.com/q/23192184/Tom_Wilkinson_(actor)> <http://stackoverflow.com/q/23192184/isCalled> "Tom Wilkinson" .
<http://stackoverflow.com/q/23192184/Tom_Wilkinson_(actor)> <http://stackoverflow.com/q/23192184/actedIn> "Cassandras_Dream" .

因为你用 Python 标记了它,你可能会找到 RDFlib比 Jena 更有用,但这里真正的问题应该是关于如何进行转换,而不是库请求(因为库请求与 Stack Overflow 无关)。

关于python - 将字符串分解为主谓词和宾语的三元组(三个字段的元组)。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23192184/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com