共用方式為


TextAnalysisClient class

用戶端,用於與 Azure 認知語言服務中的文字分析功能互動。

用戶端需要語言資源的端點和驗證方法,例如 API 金鑰或 AAD。 您可以在 Azure 入口網站的 [語言資源] 頁面中找到 API 金鑰和端點。 它們會位於資源 [金鑰和端點] 頁面的 [資源管理] 底下。

驗證的範例:

API 金鑰

import { TextAnalysisClient, AzureKeyCredential } from "@azure/ai-language-text";

const endpoint = "https://<resource name>.cognitiveservices.azure.com";
const credential = new AzureKeyCredential("<api key>");

const client = new TextAnalysisClient(endpoint, credential);

Azure Active Directory

如需使用 Azure Active Directory 進行驗證的詳細資訊,請參閱 @azure/identity 套件。

import { TextAnalysisClient } from "@azure/ai-language-text";
import { DefaultAzureCredential } from "@azure/identity";

const endpoint = "https://<resource name>.cognitiveservices.azure.com";
const credential = new DefaultAzureCredential();

const client = new TextAnalysisClient(endpoint, credential);

建構函式

TextAnalysisClient(string, KeyCredential, TextAnalysisClientOptions)

使用 Language 資源的端點和 API 金鑰或 AAD 等驗證方法,建立 TextAnalysisClient 的實例。

您可以在 Azure 入口網站的 [語言資源] 頁面中找到 API 金鑰和端點。 它們會位於資源 [金鑰和端點] 頁面的 [資源管理] 底下。

import { TextAnalysisClient, AzureKeyCredential } from "@azure/ai-language-text";

const endpoint = "https://<resource name>.cognitiveservices.azure.com";
const credential = new AzureKeyCredential("<api key>");

const client = new TextAnalysisClient(endpoint, credential);
TextAnalysisClient(string, TokenCredential, TextAnalysisClientOptions)

使用 Language 資源的端點和 API 金鑰或 AAD 等驗證方法,建立 TextAnalysisClient 的實例。

您可以在 Azure 入口網站的 [語言資源] 頁面中找到 API 金鑰和端點。 它們會位於資源 [金鑰和端點] 頁面的 [資源管理] 底下。

如需使用 Azure Active Directory 進行驗證的詳細資訊,請參閱 @azure/identity 套件。

import { TextAnalysisClient } from "@azure/ai-language-text";
import { DefaultAzureCredential } from "@azure/identity";

const endpoint = "https://<resource name>.cognitiveservices.azure.com";
const credential = new DefaultAzureCredential();

const client = new TextAnalysisClient(endpoint, credential);

方法

analyze<ActionName>(ActionName, LanguageDetectionInput[], AnalyzeActionParameters<ActionName> & TextAnalysisOperationOptions)

執行預測模型來判斷傳入輸入字串所寫入的語言,並針對每個字串傳回偵測到的語言,以及指出模型對推斷語言正確信賴的分數。 接近 1 的分數表示結果的高確定性。 支援 120 種語言。

如需數據限制,請參閱 https://docs.microsoft.com//azure/cognitive-services/language-service/concepts/data-limits

例子

語言偵測

const documents = [<input strings>];
const countryHint = "us";
const results = await client.analyze("LanguageDetection", documents, countryHint);

for (let i = 0; i < results.length; i++) {
  const result = results[i];
  if (result.error) {
    // a document has an error instead of results
  } else {
    const { name, confidenceScore, iso6391Name } = result.primaryLanguage;
  }
}

如需語言偵測的詳細資訊,請參閱 https://docs.microsoft.com//azure/cognitive-services/language-service/language-detection/overview

analyze<ActionName>(ActionName, string[], string, AnalyzeActionParameters<ActionName> & TextAnalysisOperationOptions)

執行預測模型來判斷傳入輸入字串所寫入的語言,並針對每個字串傳回偵測到的語言,以及指出模型對推斷語言正確信賴的分數。 接近 1 的分數表示結果的高確定性。 支援 120 種語言。

如需數據限制,請參閱 https://docs.microsoft.com//azure/cognitive-services/language-service/concepts/data-limits

例子

語言偵測

const documents = [<input strings>];
const countryHint = "us";
const results = await client.analyze("LanguageDetection", documents, countryHint);

for (const result of results) {
  if (result.error) {
    // a document has an error instead of results
  } else {
    const { name, confidenceScore, iso6391Name } = result.primaryLanguage;
  }
}

如需語言偵測的詳細資訊,請參閱 https://docs.microsoft.com//azure/cognitive-services/language-service/language-detection/overview

analyze<ActionName>(ActionName, string[], string, AnalyzeActionParameters<ActionName> & TextAnalysisOperationOptions)

執行預測模型,以在輸入字串上執行選擇的動作。 如需支持的動作清單,請參閱 $AnalyzeActionName

結果陣列中每個專案的版面配置取決於選擇的動作。 例如,每個 PIIEntityRecognition 文件結果都是由 entitiesredactedText 所組成,其中前者是文字中所有 Pii 實體的清單,後者是所有這類 Pii 實體經過修訂后的原始文字。

如需數據限制,請參閱 https://docs.microsoft.com//azure/cognitive-services/language-service/concepts/data-limits

例子

意見採礦

const documents = ["The food and service aren't the best"];
const results = await client.analyze("SentimentAnalysis", documents, {
  includeOpinionMining: true,
});

for (const result of results) {
  if (result.error) {
    // a document has an error instead of results
  } else {
    const { sentiment, confidenceScores, sentences } = result;
    for (const { sentiment, confidenceScores, opinions } of sentences) {
      for (const { target, assessments } of opinions) {
        const { text, sentiment, confidenceScores } = target;
        for (const { text, sentiment } of assessments) {
          // Do something
        }
      }
    }
  }
}

如需意見採礦的詳細資訊,請參閱 https://docs.microsoft.com//azure/cognitive-services/language-service/sentiment-opinion-mining/overview

個人標識資訊

const documents = [<input strings>];
const languageCode = "en";
const categoriesFilter = [KnownPiiCategory.USSocialSecurityNumber];
const domainFilter = KnownPiiDomain.Phi;
const results = await client.analyze("PiiEntityRecognition", documents, languageCode, {
  domainFilter, categoriesFilter
});

for (const result of results) {
  if (result.error) {
    // a document has an error instead of results
  } else {
    const { entities, redactedText } = result;
    for (const { text, category, confidenceScore, length, offset } of entities) {
      // Do something
    }
  }
}

如需個人標識信息的詳細資訊,請參閱 https://docs.microsoft.com//azure/cognitive-services/language-service/personally-identifiable-information/overview

analyze<ActionName>(ActionName, TextDocumentInput[], AnalyzeActionParameters<ActionName> & TextAnalysisOperationOptions)

執行預測模型,以對輸入檔執行選擇的動作。 如需支持的動作清單,請參閱 $AnalyzeActionName

結果陣列中每個專案的版面配置取決於選擇的動作。 例如,每個 PIIEntityRecognition 文件結果都是由 entitiesredactedText 所組成,其中前者是文字中所有 Pii 實體的清單,後者是所有這類 Pii 實體經過修訂后的原始文字。

如需數據限制,請參閱 https://docs.microsoft.com//azure/cognitive-services/language-service/concepts/data-limits

例子

意見採礦

const documents = [{
 id: "1",
 text: "The food and service aren't the best",
 language: "en"
}];
const results = await client.analyze("SentimentAnalysis", documents, {
  includeOpinionMining: true,
});

for (const result of results) {
  if (result.error) {
    // a document has an error instead of results
  } else {
    const { sentiment, confidenceScores, sentences } = result;
    for (const { sentiment, confidenceScores, opinions } of sentences) {
      for (const { target, assessments } of opinions) {
        const { text, sentiment, confidenceScores } = target;
        for (const { text, sentiment } of assessments) {
          // Do something
        }
      }
    }
  }
}

如需意見採礦的詳細資訊,請參閱 https://docs.microsoft.com//azure/cognitive-services/language-service/sentiment-opinion-mining/overview

個人標識資訊

const documents = [<input documents>];
const categoriesFilter = [KnownPiiCategory.USSocialSecurityNumber];
const domainFilter = KnownPiiDomain.Phi;
const results = await client.analyze("PiiEntityRecognition", documents, {
  domainFilter, categoriesFilter
});

for (const result of results) {
  if (result.error) {
    // a document has an error instead of results
  } else {
    const { entities, redactedText } = result;
    for (const { text, category, confidenceScore, length, offset } of entities) {
      // Do something
    }
  }
}

如需個人標識信息的詳細資訊,請參閱 https://docs.microsoft.com//azure/cognitive-services/language-service/personally-identifiable-information/overview

beginAnalyzeBatch(AnalyzeBatchAction[], string[], string, BeginAnalyzeBatchOptions)

在輸入檔上執行動作的陣列(批次)。 每個動作都有 kind 欄位,指定動作的性質。 如需支持的動作清單,請參閱 $AnalyzeBatchActionNames。 除了 kind之外,動作也可以有其他參數,例如 disableServiceLogsmodelVersion

結果陣列包含這些輸入動作的結果,其中每個專案也有指定結果類型的 kind 字段。

如需數據限制,請參閱 https://docs.microsoft.com//azure/cognitive-services/language-service/concepts/data-limits

例子

關鍵片語擷取和 Pii 實體辨識

const poller = await client.beginAnalyzeBatch(
 [{ kind: "KeyPhraseExtraction" }, { kind: "PiiEntityRecognition" }],
 documents
);
const actionResults = await poller.pollUntilDone();

for await (const actionResult of actionResults) {
 if (actionResult.error) {
   throw new Error(`Unexpected error`);
 }
 switch (actionResult.kind) {
   case "KeyPhraseExtraction": {
     for (const doc of actionResult.results) {
       // do something
     }
     break;
   }
   case "PiiEntityRecognition": {
     for (const doc of actionResult.results) {
       // do something
     }
     break;
   }
 }
}
beginAnalyzeBatch(AnalyzeBatchAction[], TextDocumentInput[], BeginAnalyzeBatchOptions)

在輸入檔上執行動作的陣列(批次)。 每個動作都有 kind 欄位,指定動作的性質。 如需支持的動作清單,請參閱 $AnalyzeBatchActionNames。 除了 kind之外,動作也可以有其他參數,例如 disableServiceLogsmodelVersion

結果陣列包含這些輸入動作的結果,其中每個專案也有指定結果類型的 kind 字段。

如需數據限制,請參閱 https://docs.microsoft.com//azure/cognitive-services/language-service/concepts/data-limits

例子

Keyphrase 擷取和 Pii 實體辨識

const poller = await client.beginAnalyzeBatch(
 [{ kind: "KeyPhraseExtraction" }, { kind: "PiiEntityRecognition" }],
 documents
);
const actionResults = await poller.pollUntilDone();

for await (const actionResult of actionResults) {
 if (actionResult.error) {
   throw new Error(`Unexpected error`);
 }
 switch (actionResult.kind) {
   case "KeyPhraseExtraction": {
     for (const doc of actionResult.results) {
       // do something
     }
     break;
   }
   case "PiiEntityRecognition": {
     for (const doc of actionResult.results) {
       // do something
     }
     break;
   }
 }
}
restoreAnalyzeBatchPoller(string, RestoreAnalyzeBatchPollerOptions)

從另一個輪詢程式的串行化狀態建立輪詢器。 當您想要在不同的主機上建立輪詢器,或在原始輪詢器不在範圍內之後建構投票器時,這非常有用。

建構函式詳細資料

TextAnalysisClient(string, KeyCredential, TextAnalysisClientOptions)

使用 Language 資源的端點和 API 金鑰或 AAD 等驗證方法,建立 TextAnalysisClient 的實例。

您可以在 Azure 入口網站的 [語言資源] 頁面中找到 API 金鑰和端點。 它們會位於資源 [金鑰和端點] 頁面的 [資源管理] 底下。

import { TextAnalysisClient, AzureKeyCredential } from "@azure/ai-language-text";

const endpoint = "https://<resource name>.cognitiveservices.azure.com";
const credential = new AzureKeyCredential("<api key>");

const client = new TextAnalysisClient(endpoint, credential);
new TextAnalysisClient(endpointUrl: string, credential: KeyCredential, options?: TextAnalysisClientOptions)

參數

endpointUrl

string

認知語言服務資源端點的 URL

credential
KeyCredential

用來驗證服務要求的金鑰認證。

options
TextAnalysisClientOptions

用來設定 TextAnalytics 用戶端。

TextAnalysisClient(string, TokenCredential, TextAnalysisClientOptions)

使用 Language 資源的端點和 API 金鑰或 AAD 等驗證方法,建立 TextAnalysisClient 的實例。

您可以在 Azure 入口網站的 [語言資源] 頁面中找到 API 金鑰和端點。 它們會位於資源 [金鑰和端點] 頁面的 [資源管理] 底下。

如需使用 Azure Active Directory 進行驗證的詳細資訊,請參閱 @azure/identity 套件。

import { TextAnalysisClient } from "@azure/ai-language-text";
import { DefaultAzureCredential } from "@azure/identity";

const endpoint = "https://<resource name>.cognitiveservices.azure.com";
const credential = new DefaultAzureCredential();

const client = new TextAnalysisClient(endpoint, credential);
new TextAnalysisClient(endpointUrl: string, credential: TokenCredential, options?: TextAnalysisClientOptions)

參數

endpointUrl

string

認知語言服務資源端點的 URL

credential
TokenCredential

用來驗證服務要求的令牌認證。

options
TextAnalysisClientOptions

用來設定 TextAnalytics 用戶端。

方法詳細資料

analyze<ActionName>(ActionName, LanguageDetectionInput[], AnalyzeActionParameters<ActionName> & TextAnalysisOperationOptions)

執行預測模型來判斷傳入輸入字串所寫入的語言,並針對每個字串傳回偵測到的語言,以及指出模型對推斷語言正確信賴的分數。 接近 1 的分數表示結果的高確定性。 支援 120 種語言。

如需數據限制,請參閱 https://docs.microsoft.com//azure/cognitive-services/language-service/concepts/data-limits

例子

語言偵測

const documents = [<input strings>];
const countryHint = "us";
const results = await client.analyze("LanguageDetection", documents, countryHint);

for (let i = 0; i < results.length; i++) {
  const result = results[i];
  if (result.error) {
    // a document has an error instead of results
  } else {
    const { name, confidenceScore, iso6391Name } = result.primaryLanguage;
  }
}

如需語言偵測的詳細資訊,請參閱 https://docs.microsoft.com//azure/cognitive-services/language-service/language-detection/overview

function analyze<ActionName>(actionName: ActionName, documents: LanguageDetectionInput[], options?: AnalyzeActionParameters<ActionName> & TextAnalysisOperationOptions): Promise<AnalyzeResult<ActionName>>

參數

actionName

ActionName

要對輸入檔執行的動作名稱,請參閱 $AnalyzeActionName

documents

LanguageDetectionInput[]

要分析的輸入檔

options

AnalyzeActionParameters<ActionName> & TextAnalysisOperationOptions

作業的選擇性動作參數和設定

傳回

Promise<AnalyzeResult<ActionName>>

結果陣列,其中每個元素都包含對應輸入檔的主要語言。

analyze<ActionName>(ActionName, string[], string, AnalyzeActionParameters<ActionName> & TextAnalysisOperationOptions)

執行預測模型來判斷傳入輸入字串所寫入的語言,並針對每個字串傳回偵測到的語言,以及指出模型對推斷語言正確信賴的分數。 接近 1 的分數表示結果的高確定性。 支援 120 種語言。

如需數據限制,請參閱 https://docs.microsoft.com//azure/cognitive-services/language-service/concepts/data-limits

例子

語言偵測

const documents = [<input strings>];
const countryHint = "us";
const results = await client.analyze("LanguageDetection", documents, countryHint);

for (const result of results) {
  if (result.error) {
    // a document has an error instead of results
  } else {
    const { name, confidenceScore, iso6391Name } = result.primaryLanguage;
  }
}

如需語言偵測的詳細資訊,請參閱 https://docs.microsoft.com//azure/cognitive-services/language-service/language-detection/overview

function analyze<ActionName>(actionName: ActionName, documents: string[], countryHint?: string, options?: AnalyzeActionParameters<ActionName> & TextAnalysisOperationOptions): Promise<AnalyzeResult<ActionName>>

參數

actionName

ActionName

要對輸入檔執行的動作名稱,請參閱 $AnalyzeActionName

documents

string[]

要分析的輸入檔

countryHint

string

表示所有輸入字串的原點國家/地區,以協助模型預測其寫入的語言。 如果未指定,此值將會設定為 TextAnalysisClientOptions中的預設國家/地區提示。 如果設定為空字串或字串 「none」 則服務會套用明確取消設定國家/地區的模型。 相同的國家/地區提示會套用至輸入集合中的所有字串。

options

AnalyzeActionParameters<ActionName> & TextAnalysisOperationOptions

作業的選擇性動作參數和設定

傳回

Promise<AnalyzeResult<ActionName>>

結果陣列,其中每個元素都包含對應輸入檔的主要語言。

analyze<ActionName>(ActionName, string[], string, AnalyzeActionParameters<ActionName> & TextAnalysisOperationOptions)

執行預測模型,以在輸入字串上執行選擇的動作。 如需支持的動作清單,請參閱 $AnalyzeActionName

結果陣列中每個專案的版面配置取決於選擇的動作。 例如,每個 PIIEntityRecognition 文件結果都是由 entitiesredactedText 所組成,其中前者是文字中所有 Pii 實體的清單,後者是所有這類 Pii 實體經過修訂后的原始文字。

如需數據限制,請參閱 https://docs.microsoft.com//azure/cognitive-services/language-service/concepts/data-limits

例子

意見採礦

const documents = ["The food and service aren't the best"];
const results = await client.analyze("SentimentAnalysis", documents, {
  includeOpinionMining: true,
});

for (const result of results) {
  if (result.error) {
    // a document has an error instead of results
  } else {
    const { sentiment, confidenceScores, sentences } = result;
    for (const { sentiment, confidenceScores, opinions } of sentences) {
      for (const { target, assessments } of opinions) {
        const { text, sentiment, confidenceScores } = target;
        for (const { text, sentiment } of assessments) {
          // Do something
        }
      }
    }
  }
}

如需意見採礦的詳細資訊,請參閱 https://docs.microsoft.com//azure/cognitive-services/language-service/sentiment-opinion-mining/overview

個人標識資訊

const documents = [<input strings>];
const languageCode = "en";
const categoriesFilter = [KnownPiiCategory.USSocialSecurityNumber];
const domainFilter = KnownPiiDomain.Phi;
const results = await client.analyze("PiiEntityRecognition", documents, languageCode, {
  domainFilter, categoriesFilter
});

for (const result of results) {
  if (result.error) {
    // a document has an error instead of results
  } else {
    const { entities, redactedText } = result;
    for (const { text, category, confidenceScore, length, offset } of entities) {
      // Do something
    }
  }
}

如需個人標識信息的詳細資訊,請參閱 https://docs.microsoft.com//azure/cognitive-services/language-service/personally-identifiable-information/overview

function analyze<ActionName>(actionName: ActionName, documents: string[], languageCode?: string, options?: AnalyzeActionParameters<ActionName> & TextAnalysisOperationOptions): Promise<AnalyzeResult<ActionName>>

參數

actionName

ActionName

要對輸入檔執行的動作名稱,請參閱 $AnalyzeActionName

documents

string[]

要分析的輸入檔

languageCode

string

寫入所有輸入字串之語言的程序代碼。 如果未指定,此值將會設定為 TextAnalysisClientOptions的默認語言。 如果設定為空字串,服務將會套用模型,其中語言明確設定為 「None」。。 語言支援會因動作而異,例如,如需實體辨識動作所支援語言的詳細資訊,請參閱 https://docs.microsoft.com//azure/cognitive-services/language-service/named-entity-recognition/language-support。 如果設定為 「auto」,服務會自動從輸入文字推斷語言。

options

AnalyzeActionParameters<ActionName> & TextAnalysisOperationOptions

作業的選擇性動作參數和設定

傳回

Promise<AnalyzeResult<ActionName>>

對應至輸入檔的結果陣列

analyze<ActionName>(ActionName, TextDocumentInput[], AnalyzeActionParameters<ActionName> & TextAnalysisOperationOptions)

執行預測模型,以對輸入檔執行選擇的動作。 如需支持的動作清單,請參閱 $AnalyzeActionName

結果陣列中每個專案的版面配置取決於選擇的動作。 例如,每個 PIIEntityRecognition 文件結果都是由 entitiesredactedText 所組成,其中前者是文字中所有 Pii 實體的清單,後者是所有這類 Pii 實體經過修訂后的原始文字。

如需數據限制,請參閱 https://docs.microsoft.com//azure/cognitive-services/language-service/concepts/data-limits

例子

意見採礦

const documents = [{
 id: "1",
 text: "The food and service aren't the best",
 language: "en"
}];
const results = await client.analyze("SentimentAnalysis", documents, {
  includeOpinionMining: true,
});

for (const result of results) {
  if (result.error) {
    // a document has an error instead of results
  } else {
    const { sentiment, confidenceScores, sentences } = result;
    for (const { sentiment, confidenceScores, opinions } of sentences) {
      for (const { target, assessments } of opinions) {
        const { text, sentiment, confidenceScores } = target;
        for (const { text, sentiment } of assessments) {
          // Do something
        }
      }
    }
  }
}

如需意見採礦的詳細資訊,請參閱 https://docs.microsoft.com//azure/cognitive-services/language-service/sentiment-opinion-mining/overview

個人標識資訊

const documents = [<input documents>];
const categoriesFilter = [KnownPiiCategory.USSocialSecurityNumber];
const domainFilter = KnownPiiDomain.Phi;
const results = await client.analyze("PiiEntityRecognition", documents, {
  domainFilter, categoriesFilter
});

for (const result of results) {
  if (result.error) {
    // a document has an error instead of results
  } else {
    const { entities, redactedText } = result;
    for (const { text, category, confidenceScore, length, offset } of entities) {
      // Do something
    }
  }
}

如需個人標識信息的詳細資訊,請參閱 https://docs.microsoft.com//azure/cognitive-services/language-service/personally-identifiable-information/overview

function analyze<ActionName>(actionName: ActionName, documents: TextDocumentInput[], options?: AnalyzeActionParameters<ActionName> & TextAnalysisOperationOptions): Promise<AnalyzeResult<ActionName>>

參數

actionName

ActionName

要對輸入檔執行的動作名稱,請參閱 $AnalyzeActionName

documents

TextDocumentInput[]

要分析的輸入檔

options

AnalyzeActionParameters<ActionName> & TextAnalysisOperationOptions

作業的選擇性動作參數和設定

傳回

Promise<AnalyzeResult<ActionName>>

對應至輸入檔的結果陣列

beginAnalyzeBatch(AnalyzeBatchAction[], string[], string, BeginAnalyzeBatchOptions)

在輸入檔上執行動作的陣列(批次)。 每個動作都有 kind 欄位,指定動作的性質。 如需支持的動作清單,請參閱 $AnalyzeBatchActionNames。 除了 kind之外,動作也可以有其他參數,例如 disableServiceLogsmodelVersion

結果陣列包含這些輸入動作的結果,其中每個專案也有指定結果類型的 kind 字段。

如需數據限制,請參閱 https://docs.microsoft.com//azure/cognitive-services/language-service/concepts/data-limits

例子

關鍵片語擷取和 Pii 實體辨識

const poller = await client.beginAnalyzeBatch(
 [{ kind: "KeyPhraseExtraction" }, { kind: "PiiEntityRecognition" }],
 documents
);
const actionResults = await poller.pollUntilDone();

for await (const actionResult of actionResults) {
 if (actionResult.error) {
   throw new Error(`Unexpected error`);
 }
 switch (actionResult.kind) {
   case "KeyPhraseExtraction": {
     for (const doc of actionResult.results) {
       // do something
     }
     break;
   }
   case "PiiEntityRecognition": {
     for (const doc of actionResult.results) {
       // do something
     }
     break;
   }
 }
}
function beginAnalyzeBatch(actions: AnalyzeBatchAction[], documents: string[], languageCode?: string, options?: BeginAnalyzeBatchOptions): Promise<AnalyzeBatchPoller>

參數

actions

AnalyzeBatchAction[]

將在輸入檔上執行的動作陣列

documents

string[]

要分析的輸入檔

languageCode

string

寫入所有輸入字串之語言的程序代碼。 如果未指定,此值將會設定為 TextAnalysisClientOptions的默認語言。 如果設定為空字串,服務將會套用模型,其中語言明確設定為 「None」。。 語言支援會因動作而異,例如,如需實體辨識動作所支援語言的詳細資訊,請參閱 https://docs.microsoft.com//azure/cognitive-services/language-service/named-entity-recognition/language-support。 如果設定為 「auto」,服務會自動從輸入文字推斷語言。

options
BeginAnalyzeBatchOptions

作業的選擇性設定

傳回

對應至輸入動作的結果陣列

beginAnalyzeBatch(AnalyzeBatchAction[], TextDocumentInput[], BeginAnalyzeBatchOptions)

在輸入檔上執行動作的陣列(批次)。 每個動作都有 kind 欄位,指定動作的性質。 如需支持的動作清單,請參閱 $AnalyzeBatchActionNames。 除了 kind之外,動作也可以有其他參數,例如 disableServiceLogsmodelVersion

結果陣列包含這些輸入動作的結果,其中每個專案也有指定結果類型的 kind 字段。

如需數據限制,請參閱 https://docs.microsoft.com//azure/cognitive-services/language-service/concepts/data-limits

例子

Keyphrase 擷取和 Pii 實體辨識

const poller = await client.beginAnalyzeBatch(
 [{ kind: "KeyPhraseExtraction" }, { kind: "PiiEntityRecognition" }],
 documents
);
const actionResults = await poller.pollUntilDone();

for await (const actionResult of actionResults) {
 if (actionResult.error) {
   throw new Error(`Unexpected error`);
 }
 switch (actionResult.kind) {
   case "KeyPhraseExtraction": {
     for (const doc of actionResult.results) {
       // do something
     }
     break;
   }
   case "PiiEntityRecognition": {
     for (const doc of actionResult.results) {
       // do something
     }
     break;
   }
 }
}
function beginAnalyzeBatch(actions: AnalyzeBatchAction[], documents: TextDocumentInput[], options?: BeginAnalyzeBatchOptions): Promise<AnalyzeBatchPoller>

參數

actions

AnalyzeBatchAction[]

將在輸入檔上執行的動作陣列

documents

TextDocumentInput[]

要分析的輸入檔

options
BeginAnalyzeBatchOptions

作業的選擇性設定

傳回

對應至輸入動作的結果陣列

restoreAnalyzeBatchPoller(string, RestoreAnalyzeBatchPollerOptions)

從另一個輪詢程式的串行化狀態建立輪詢器。 當您想要在不同的主機上建立輪詢器,或在原始輪詢器不在範圍內之後建構投票器時,這非常有用。

function restoreAnalyzeBatchPoller(serializedState: string, options?: RestoreAnalyzeBatchPollerOptions): Promise<AnalyzeBatchPoller>

參數

serializedState

string

另一個輪詢程式的串行化狀態。 這是 poller.toString() 的結果

options
RestoreAnalyzeBatchPollerOptions

作業的選擇性設定

client.beginAnalyzeBatch 傳回將解決給投票者的承諾。 輪詢器的狀態可以串行化,並用來建立另一個輪詢程式,如下所示:

const serializedState = poller.toString();
const rehydratedPoller = await client.createAnalyzeBatchPoller(serializedState);
const actionResults = await rehydratedPoller.pollUntilDone();

傳回