2

我对 TypeScript 非常陌生,尤其是对 Object(Sets) 的自定义 Palantir 实现。我要存档的内容:我想将 ObjectSet 过滤为某些特定值。然后我想返回这些值中的第一个。事实上,我只想返回一行。到目前为止我所做的:

    @Function()
    public nextUnprocessedValueString(inputObject: ObjectSet<CombinedSentencesForTagging>): ObjectSet<CombinedSentencesForTagging>{
        const result = Objects.search().combinedSentencesForTagging().filter(f => f.customerFeedback.exactMatch('i like it very much.'))
        return result

结果如下所示: 结果

我只需要第一行(或随机行)。

谢谢!

4

1 回答 1

2

试试这个:

@Function()
public nextUnprocessedValueString(inputObject: ObjectSet<CombinedSentencesForTagging>): CombinedSentencesForTagging {
    const result = 
           inputObject.filter(f => f.customerFeedback.exactMatch('i like it very much.'))
                      .orderBy(f => f.customerFeedback.asc())
                      .take(1);
    
    return result[0];
}

以下是我对原始函数所做的更改:

  1. 将返回类型更改为单个CombinedSentencesForTagging对象。
  2. 修改了要在函数参数filter中指定的行上运行inputObject
  3. 使用orderByand takefilter 子句只选择一个过滤结果。
于 2021-06-15T14:08:27.913 回答