0

我正在编写一个收集三个输入的动作。第一个是必需的,但第二个和第三个是可选的。因为第二个和第三个选项的类型相似,所以有时第三个类型被填充,而第二个不填充。

即,我要传入一本书,或者书+页,或者书+页+行号

我显然可以通过执行多个(几乎相同)操作或在端点本身来处理这个问题,但是是否可以通过另一个输入的存在来确定单个操作输入的依赖关系?

动作目前看起来像......

collect {
  input (book) {
    type (String)
    min (Required) max (One)
  }
  input (page) {
    type (Integer)
    min (Optional) max (One)
  }
  input (line) {
    type (Integer)
    min (Optional) max (One)
  }
}

4

2 回答 2

0

default-init鉴于您的用例,以下列方式使用是有意义的:

collect {
  input (book) {
    type (String)
    min (Required) max (One)
  }
  input (page) {
    type (Integer)
    min (Optional) max (One)
    default-init {
      if (!exists(page)) {
        intent {
          goal: YOUR ACTION HERE
          value: Integer (1)
        }
      }
    }
  }
  input (line) {
    type (Integer)
    min (Optional) max (One)
    default-init {
      if (!exists(line)) {
        intent {
          goal: YOUR ACTION HERE
          value: Integer (1)
        }
      }
    }
  }
}

如果用户未提供页码和行号,这将允许它们默认为 1。

于 2019-03-18T23:51:59.673 回答
0

看起来最好的选择(到目前为止只有我能找到)是创建修改原件,然后添加第二个。最后,添加一个新action-endpointendpoints.

ReadBook删除了可选

action (ReadBook) {
  description ("Read a page from a book (first if page isn't provided)."")
  type (Calculation)
  collect {
    input (book) {
      type (Book)
      min (Required) max (One)
    }
    input (page) {
      type (PageNum)
      min (Optional) max (One)
    }
  }
  output (Passage)
}

ReadBookLine需要所有输入

action (ReadBookLine) {
  description (Read a line from a book.)
  type (Calculation)
  collect {
    input (book) {
      type (Book)
      min (Required) max (One)
    }
    input (page) {
      type (PageNum)
      min (Required) max (One)
    }
    input (line) {
      type (LineNum)
      min (Required) max (One)
    }
  }
  output (Passage)
}

端点

endpoints {
    action-endpoint (ReadBook) {
      accepted-inputs (book, page)
      remote-endpoint ("https://.../read_book) {
        method (POST)
      }
    }
    action-endpoint (ReadBookLine) {
      accepted-inputs (book, page, line)
      remote-endpoint ("https://.../read_book") {
        method (POST)
      }
    }
  }
}
于 2019-03-19T20:51:54.633 回答