gpt4 book ai didi

java - 组合检查句子中所有实体的关系

转载 作者:行者123 更新时间:2023-12-01 11:36:36 25 4
gpt4 key购买 nike

我有一个以下形式的句子:

<sentence> 0
A sports article in some copies on Sunday about <LOCATION>Boston</LOCATION> 's 1-0 victory against <LOCATION>San Francisco</LOCATION> referred incorrectly to the history of the interleague series between the <ORGANIZATION>Red Sox</ORGANIZATION> and the <ORGANIZATION>Giants</ORGANIZATION> .
</sentence>

句子中引用了实体,即

Boston
San Francisco
Red Sox
Giants

我想“组合”评估它们以确定它们是否有某种关系。

所以我有一些函数可以告诉我它们是否相关,我想编写一个函数来检查,例如:

Boston        X San Francisco
Boston X Red Sox
Boston X Giants
San Francisco X Boston
San Francisco X Red Sox
San Francisco X Giants
Red Sox X Boston
Red Sox X San Francisco
Red Sox X Giants
Giants X Boston
Giants X San Francisco
Giants X Red Sox

如何编写这样的函数?

最佳答案

对于您所要求的“完整正方形,排除对角线”

string[] teams = {"Boston","San Francisco","Red Sox","Giants"};
for (string home:teams)
{
for (string away:teams)
{
if (home==away) continue;
System.out.println(home + " x " + away);
}
}

您也可以使用带有 i、j 等的 for 循环。如果您想删除 A X B 和 B X A 的重复项,通常需要使用这种情况

关于java - 组合检查句子中所有实体的关系,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29915145/

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