java中的'predicate.arg(1)'和'predicate.arity'是什么意思

What is the meaning of 'predicate.arg(1)' and 'predicate.arity' in java

我有一些 java 代码正在尝试转换为 vb.net。它使用 'predicates',一个我直到现在才知道的功能,但它也存在于 vb.net 中。

所以我阅读了关于它的文档,但是其中 none 解释了我的 java 代码,特别是,如果您有一个声明为谓词的变量 'p', p.arity 做什么,p.arg(0) 和 p.arg(1) return 做什么?

我的一般印象是谓词采用一组对象,return 是满足特定条件的子集,(例如,给定所有篮球运动员的集合,return 只有那些超过 6 英尺高)。但是下面的代码似乎与此无关:

    // st is assumed to be a list of ECHO predicates
    //
  private void parseInput(StreamTokenizer st) throws IOException
  {

while (st.nextToken() != StreamTokenizer.TT_EOF) {
  st.pushBack();
  Predicate p = new Predicate(st);
  parsePredicate(p);
} // while
  }


  // PRE: p is non-null
  // POST: performs the additions to the ECHO graph required by the
  //       ECHO predicate; if p is not a legal ECHO predicate, an 
  //       IOException is thrown
  //
  private void parsePredicate(Predicate p) throws IOException
 {
Assert.notNull(p);
String name = p.name();

if (name.equalsIgnoreCase(explainPred)) {
  parseExplain(p);
} else if (name.equalsIgnoreCase(dataPred)) {
  parseData(p);
} else if (name.equalsIgnoreCase(contradictPred)) {
  parseContradict(p);
} else if (name.equalsIgnoreCase(analogyPred)) {
  parseAnalogy(p);
} else if (name.equalsIgnoreCase(propositionPred)) {
  parseProposition(p);
} else {
  throw new IOException("ECHO: "+name+" is not a legal predicate name. "+
                                                "Must be one of "+explainPred+", "+dataPred+", "+
                                                contradictPred+", or "+analogyPred);
} // if
  }

  //
  // PRE: p's name is explainPred
  // POST: adds the given explanation predicate to ECHO, adding all necessary
  //       links; throws an exception if p is not a legal explains predicate
  //
  private void parseExplain(Predicate p) throws IOException
  {
//msg("in parseExplain...");
int arity = p.arity();
float weight;
List propList;
String explainee;

if (arity == 2) {
  //msg("arity == 2");
  propList = (List)p.arg(0);
  explainee = (String)p.arg(1);
  weight = (float)explainWeight(propList.length());
} else if (arity == 3) {
  //msg("arity == 3");
  propList = (List)p.arg(0);
  explainee = (String)p.arg(1);
  float strength = Float.valueOf((String)p.arg(2)).floatValue();
  weight = (float)(strength*explainWeight(propList.length()));
} else {
  throw new IOException("ECHO: an explains predicate must have 2 or 3 "+
                                                "arguments: "+p);
    } // if

在这种情况下,我假设如下:

arity 是函数采用的参数数量。您可以看到,在检查 arity 是否等于 2 之后,它读取了两个参数(arg(0) 和 arg(1))。所以 arg 只是在给定索引处获取 parameter/argument 的方法。

那么当arity为3时,可以得到三个args; 0, 1, 2