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

wf82jlnq  于 2021-07-13  发布在  Java
关注(0)|答案(1)|浏览(252)

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

<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

如何编写这样的函数?

np8igboo

np8igboo1#

对于“全正方形,排除对角线”,正如你所要求的

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);
  }
}

你也可以使用for循环和i,j等。如果你想消除重复的a x b和b x a,你通常需要使用这种情况

相关问题