日期:2014-05-20  浏览次数:20710 次

谁能看看这两个递归函数有什么区别
这个递归函数
public static void searchForChains(Synset source,Synset target,Chain inherit)
{
if(inherit.size() < max+1)
{
try
{
PointerTargetNodeList sourceParent =
PointerUtils.getInstance().getDirectHypernyms(source);
int size1 = sourceParent.size();
if(0 != size1)
{
Chain temp1 = (Chain)inherit.clone();
searchForChain(sourceParent,target,temp1,1);
}


PointerTargetNodeList sourceChild =
PointerUtils.getInstance().getDirectHyponyms(source);
int size2 = sourceChild.size();
if(0 != size2)
{

Chain temp2 = (Chain)inherit.clone();
searchForChain(sourceChild,target,temp2,2);
}

PointerTargetNodeList sourceHolonym =
PointerUtils.getInstance().getHolonyms(source);
int size3 = sourceHolonym.size();
if(0 != size3)
{

Chain temp3 = (Chain)inherit.clone();
searchForChain(sourceHolonym,target,temp3,3);
}

PointerTargetNodeList sourceMeronym =
PointerUtils.getInstance().getMeronyms(source);
int size4 = sourceMeronym.size();
if(0 != size4)
{
Chain temp4 = (Chain)inherit.clone();
searchForChain(sourceMeronym,target,temp4,4);
}
}
catch(JWNLException e)
{
e.printStackTrace();
}
}
else
{
return;
}
}
public static void searchForChain(PointerTargetNodeList list,Synset target,Chain inherit,int type)
{
for(Iterator it = list.iterator();it.hasNext();)
{
PointerTargetNode Node = (PointerTargetNode)it.next();
if(!target.equals(Node.getSynset()))
{
if(!inherit.hasCircle(Node.getSynset()))
{
Chain temp = (Chain)inherit.clone();
switch(type)
{
case 1:
temp.add(new Chain(Node.getSynset(),"hypernym",null));
break;
case 2:
temp.add(new Chain(Node.getSynset(),"hyponym",null));
break;
case 3:
temp.add(new Chain(Node.getSynset(),"holonym",null));
break;
case 4:
temp.add(new Chain(Node.getSynset(),"meronym",null));
break;
default:
break;
}
searchForChains(Node.getSynset(),target,temp);
}
else
{
return;
}
}
else
{
switch(type)
{
case 1:
inherit.add(new Chain(Node.getSynset(),"hypernym",null));
break;
case 2:
inherit.add(new Chain(Node.getSynset(),"hyponym",null));
break;
case 3:
inherit.add(new Chain(Node.getSynset(),"holonym",null));
break;
case 4:
inherit.add(new Chain(Node.getSynset(),"meronym",null));
break;
default:
break;
}
Chains.add(inherit);
return;
}
}
}
以上是两个递归函数相互调用
以下是合成的递归函数
运行结果一点都不一样(以上函数都是程序的一部分)
public static void searchForChains(Synset source,Synset target,Chain inherit)
{
if(inherit.size() < max+1)
{
try
{
PointerTargetNodeList sourceParent =
PointerUtils.getInstance().getDirectHypernyms(source);
int size1 = sourceParent.size();
if(0 != size1)
{
for(Iterator it = sourceParent.iterator();it.hasNext();)
{
PointerTargetNode Node = (PointerTargetNode)it.next();
if(!target.equals(Node.getSynset()))
{
if(!inherit.hasCircle(Node.getSynset()))
{
Chain temp1 = (Chain)inherit.clone();
temp1.add(new Chain(Node.getSynset(),"hypernym",null));