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

Combinatorially check relationship for all entities in a sentence

我有如下形式的句子:

<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

我想"combinatorially"评估它们以确定它们是否有某种关系。

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

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

这样的函数怎么写?

如您所求'full square, excluded diagonal'

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 的重复数据,通常需要使用这种情况