使用自定义关键词分析会话

概览

自定义精彩集锦的功能与智能集锦功能类似。突出显示的内容包含 CX Insights 认为对确定用户意图至关重要的关键字、短语或句子。如果存在精彩集锦,则会在返回的转写内容中添加标签。 智能精彩集锦会根据一系列预设场景自动检测精彩片段,而自定义精彩集锦则允许您指定应被识别为精彩片段的自定义条件。

自定义突出显示可以包含一个或多个词组匹配规则组。词组匹配规则组包含一条或多条规则。您可以使用以下参数来自定义规则的行为。

确定匹配的规则

您可以指定,当只有一个规则组解析为 true 时,是否应检测到突出显示;或者当所有规则组都解析为 true 时,是否应检测到突出显示。 同样,您也可以指定,如果仅满足规则组中的一条规则,或者必须满足规则组中所有规则的条件,规则组应解析为 true

使用 CX Insights API 创建自定义精彩集锦

检测指定查询字符串列表中的“任意”一个

以下示例创建了一个 PhraseMatcher 对象,该对象指示 CX Insights 在对话中出现两个短语中的任意一个时,为其添加突出显示标签。无需同时出现这两个短语,系统即可检测到精彩片段。

REST

如需了解完整的详细信息,请参阅 PhraseMatcherTypePhraseMatchRuleGroupType 参考文档。将两个 query 字段替换为 PHONECELLPHONE 后,应会生成示例输出。

在使用任何请求数据之前,请先进行以下替换:

  • PROJECT_ID:您的 Google Cloud 项目 ID。
  • DISPLAY_NAME:短语匹配器的直观易懂的名称。
  • QUERY:要匹配的字词或短语。

HTTP 方法和网址:

POST https://contactcenterinsights.googleapis.com/v1/projects/PROJECT_ID/locations/us-central1/phraseMatchers

请求 JSON 正文:

{
  "display_name": DISPLAY_NAME,
  "type": "ANY_OF",
  "active": true,
  "phrase_match_rule_groups": {
    "type": "ANY_OF",
    "phrase_match_rules": {
      "query": QUERY
      "config": {
        "exact_match_config": {}
      }
    },
    "phrase_match_rules": {
      "query": QUERY
      "config": {
        "exact_match_config": {}
      }
    }
  }
}

如需发送您的请求,请展开以下选项之一:

您应该收到类似以下内容的 JSON 响应:

{
  "name": "projects/PROJECT_ID/locations/us-central1/phraseMatchers/PHRASE_MATCHER_ID",
  "revisionId": "REVISION_ID",
  "revisionCreateTime": "2021-01-20T10:10:10.123000Z",
  "displayName": "PHONE_SERVICE",
  "type": "ANY_OF",
  "active": true,
  "phraseMatchRuleGroups": [
    {
      "type": "ANY_OF",
      "phraseMatchRules": [
        {
          "query": "PHONE",
          "config": {
            "exactMatchConfig": {}
          }
        },
        {
          "query": "CELLPHONE",
          "config": {
            "exactMatchConfig": {}
          }
        }
      ]
    }
  ],
  "activationUpdateTime": "2021-01-20T10:10:10.123000Z"
}

Python

如需向 CX Insights 进行身份验证,请设置应用默认凭据。 如需了解详情,请参阅为本地开发环境设置身份验证

from google.cloud import contact_center_insights_v1


def create_phrase_matcher_any_of(
    project_id: str,
) -> contact_center_insights_v1.PhraseMatcher:
    """Creates a phrase matcher that matches any of the specified queries.

    Args:
        project_id:
            The project identifier. For example, 'my-project'.

    Returns:
        A phrase matcher.
    """
    # Construct a parent resource.
    parent = (
        contact_center_insights_v1.ContactCenterInsightsClient.common_location_path(
            project_id, "us-central1"
        )
    )

    # Construct a phrase matcher that matches any of its rule groups.
    phrase_matcher = contact_center_insights_v1.PhraseMatcher()
    phrase_matcher.display_name = "PHONE_SERVICE"
    phrase_matcher.type_ = (
        contact_center_insights_v1.PhraseMatcher.PhraseMatcherType.ANY_OF
    )
    phrase_matcher.active = True

    # Construct a rule group to match the word "PHONE" or "CELLPHONE", ignoring case sensitivity.
    rule_group = contact_center_insights_v1.PhraseMatchRuleGroup()
    rule_group.type_ = (
        contact_center_insights_v1.PhraseMatchRuleGroup.PhraseMatchRuleGroupType.ANY_OF
    )

    for word in ["PHONE", "CELLPHONE"]:
        rule = contact_center_insights_v1.PhraseMatchRule()
        rule.query = word
        rule.config.exact_match_config = contact_center_insights_v1.ExactMatchConfig()
        rule_group.phrase_match_rules.append(rule)
    phrase_matcher.phrase_match_rule_groups.append(rule_group)

    # Call the Insights client to create a phrase matcher.
    insights_client = contact_center_insights_v1.ContactCenterInsightsClient()
    phrase_matcher = insights_client.create_phrase_matcher(
        parent=parent, phrase_matcher=phrase_matcher
    )

    print(f"Created {phrase_matcher.name}")
    return phrase_matcher

Java

如需向 CX Insights 进行身份验证,请设置应用默认凭据。 如需了解详情,请参阅为本地开发环境设置身份验证


import com.google.cloud.contactcenterinsights.v1.ContactCenterInsightsClient;
import com.google.cloud.contactcenterinsights.v1.ExactMatchConfig;
import com.google.cloud.contactcenterinsights.v1.LocationName;
import com.google.cloud.contactcenterinsights.v1.PhraseMatchRule;
import com.google.cloud.contactcenterinsights.v1.PhraseMatchRuleConfig;
import com.google.cloud.contactcenterinsights.v1.PhraseMatchRuleGroup;
import com.google.cloud.contactcenterinsights.v1.PhraseMatcher;
import java.io.IOException;

public class CreatePhraseMatcherAnyOf {

  public static void main(String[] args) throws IOException {
    // TODO(developer): Replace this variable before running the sample.
    String projectId = "my_project_id";

    createPhraseMatcherAnyOf(projectId);
  }

  public static PhraseMatcher createPhraseMatcherAnyOf(String projectId) throws IOException {
    // Initialize client that will be used to send requests. This client only needs to be created
    // once, and can be reused for multiple requests. After completing all of your requests, call
    // the "close" method on the client to safely clean up any remaining background resources.
    try (ContactCenterInsightsClient client = ContactCenterInsightsClient.create()) {
      // Construct a phrase matcher that matches any of its rule groups.
      PhraseMatcher.Builder phraseMatcher =
          PhraseMatcher.newBuilder()
              .setDisplayName("PHONE_SERVICE")
              .setTypeValue(2)
              .setActive(true);

      // Construct a rule group to match the word "PHONE" or "CELLPHONE", ignoring case sensitivity.
      PhraseMatchRuleGroup.Builder ruleGroup = PhraseMatchRuleGroup.newBuilder().setTypeValue(2);

      String[] words = {"PHONE", "CELLPHONE"};
      for (String w : words) {
        PhraseMatchRule.Builder rule =
            PhraseMatchRule.newBuilder()
                .setQuery(w)
                .setConfig(
                    PhraseMatchRuleConfig.newBuilder()
                        .setExactMatchConfig(ExactMatchConfig.newBuilder().build())
                        .build());
        ruleGroup.addPhraseMatchRules(rule.build());
      }
      phraseMatcher.addPhraseMatchRuleGroups(ruleGroup.build());

      // Construct a parent resource.
      LocationName parent = LocationName.of(projectId, "us-central1");

      // Call the Insights client to create a phrase matcher.
      PhraseMatcher response = client.createPhraseMatcher(parent, phraseMatcher.build());
      System.out.printf("Created %s%n", response.getName());
      return response;
    }
  }
}

Node.js

如需向 CX Insights 进行身份验证,请设置应用默认凭据。 如需了解详情,请参阅为本地开发环境设置身份验证

/**
 * TODO(developer): Uncomment this variable before running the sample.
 */
// const projectId = 'my_project_id';

// Imports the Contact Center Insights client.
const {
  ContactCenterInsightsClient,
} = require('@google-cloud/contact-center-insights');

// Instantiates a client.
const client = new ContactCenterInsightsClient();

async function createPhraseMatcherAnyOf() {
  const [phraseMatcher] = await client.createPhraseMatcher({
    parent: client.locationPath(projectId, 'us-central1'),
    phraseMatcher: {
      displayName: 'PHONE_SERVICE',
      type: 'ANY_OF',
      active: true,
      phraseMatchRuleGroups: [
        {
          type: 'ANY_OF',
          phraseMatchRules: [
            {
              query: 'PHONE',
              config: {
                exactMatchConfig: {},
              },
            },
            {
              query: 'CELLPHONE',
              config: {
                exactMatchConfig: {},
              },
            },
          ],
        },
      ],
    },
  });
  console.info(`Created ${phraseMatcher.name}`);
}
createPhraseMatcherAnyOf();

检测指定查询字符串列表中的“所有”查询字符串

以下示例创建了一个 PhraseMatcher 对象,该对象指示 CX Insights 为包含第一个 phraseMatchRuleGroups 中查询字词但不包含第二个 'phraseMatchRuleGroups` 中查询字词的对话添加突出显示标签。

REST

如需了解完整的详细信息,请参阅 PhraseMatcherTypePhraseMatchRuleGroupType 参考文档。将两个 query 字段替换为 PHONECELLPHONE,并将后两个 query 字段替换为 SHIPPINGDELIVERY,应该会生成示例输出。此示例指示 CX Insights 为包含“手机”和“手机”但不包含“配送”或“送货”的对话添加突出显示标签。

在使用任何请求数据之前,请先进行以下替换:

  • PROJECT_ID:您的 Google Cloud 项目 ID。
  • DISPLAY_NAME:短语匹配器的直观易懂的名称。
  • QUERY:要匹配的字词或短语。

HTTP 方法和网址:

POST https://contactcenterinsights.googleapis.com/v1/projects/PROJECT_ID/locations/us-central1/phraseMatchers

请求 JSON 正文:

{
  "display_name": DISPLAY_NAME,
  "type": "ALL_OF",
  "active": true,
  "phrase_match_rule_groups": {
    "type": "ANY_OF",
    "phrase_match_rules": {
      "query": QUERY
      "config": {
        "exact_match_config": {}
      }
    },
    "phrase_match_rules": {
      "query": QUERY
      "config": {
        "exact_match_config": {}
      }
    },
    "phrase_match_rule_groups": {
      "type": "ALL_OF",
      "phrase_match_rules": {
        "query": QUERY
        "negated": "true"
        "config": {
          "exact_match_config": {}
        }
      },
      "phrase_match_rules": {
        "query": QUERY
        "negated": "true"
        "config": {
          "exact_match_config": {}
        }
      }
    }
  }
}

如需发送您的请求,请展开以下选项之一:

您应该收到类似以下内容的 JSON 响应:

{
  "name": "projects/PROJECT_ID/locations/us-central1/phraseMatchers/PHRASE_MATCHER_ID",
  "revisionId": "456456456",
  "revisionCreateTime": "2021-01-20T10:10:10.123000Z",
  "displayName": "NON_SHIPPING_PHONE_SERVICE",
  "type": "ALL_OF",
  "active": true,
  "phraseMatchRuleGroups": [
    {
      "type": "ANY_OF",
      "phraseMatchRules": [
        {
          "query": "PHONE",
          "config": {
            "exactMatchConfig": {}
          }
        },
        {
          "query": "CELLPHONE",
          "config": {
            "exactMatchConfig": {}
          }
        }
      ]
    },
    {
      "type": "ALL_OF",
      "phraseMatchRules": [
        {
          "query": "SHIPPING",
          "negated": true,
          "config": {
            "exactMatchConfig": {}
          }
        },
        {
          "query": "DELIVERY",
          "negated": true,
          "config": {
            "exactMatchConfig": {}
          }
        }
      ]
    }
  ],
  "activationUpdateTime": "2021-01-20T10:10:10.123000Z"
}

Python

如需向 CX Insights 进行身份验证,请设置应用默认凭据。 如需了解详情,请参阅为本地开发环境设置身份验证

from google.cloud import contact_center_insights_v1


def create_phrase_matcher_all_of(
    project_id: str,
) -> contact_center_insights_v1.PhraseMatcher:
    """Creates a phrase matcher that matches all specified queries.

    Args:
        project_id:
            The project identifier. For example, 'my-project'.

    Returns:
        A phrase matcher.
    """
    # Construct a parent resource.
    parent = (
        contact_center_insights_v1.ContactCenterInsightsClient.common_location_path(
            project_id, "us-central1"
        )
    )

    # Construct a phrase matcher that matches all of its rule groups.
    phrase_matcher = contact_center_insights_v1.PhraseMatcher()
    phrase_matcher.display_name = "NON_SHIPPING_PHONE_SERVICE"
    phrase_matcher.type_ = (
        contact_center_insights_v1.PhraseMatcher.PhraseMatcherType.ALL_OF
    )
    phrase_matcher.active = True

    # Construct a rule group to match the word "PHONE" or "CELLPHONE", ignoring case sensitivity.
    rule_group_phone_or_cellphone = contact_center_insights_v1.PhraseMatchRuleGroup()
    rule_group_phone_or_cellphone.type_ = (
        contact_center_insights_v1.PhraseMatchRuleGroup.PhraseMatchRuleGroupType.ANY_OF
    )

    for word in ["PHONE", "CELLPHONE"]:
        rule = contact_center_insights_v1.PhraseMatchRule()
        rule.query = word
        rule.config.exact_match_config = contact_center_insights_v1.ExactMatchConfig()
        rule_group_phone_or_cellphone.phrase_match_rules.append(rule)
    phrase_matcher.phrase_match_rule_groups.append(rule_group_phone_or_cellphone)

    # Construct another rule group to not match the word "SHIPPING" or "DELIVERY", ignoring case sensitivity.
    rule_group_not_shipping_or_delivery = (
        contact_center_insights_v1.PhraseMatchRuleGroup()
    )
    rule_group_not_shipping_or_delivery.type_ = (
        contact_center_insights_v1.PhraseMatchRuleGroup.PhraseMatchRuleGroupType.ALL_OF
    )

    for word in ["SHIPPING", "DELIVERY"]:
        rule = contact_center_insights_v1.PhraseMatchRule()
        rule.query = word
        rule.negated = True
        rule.config.exact_match_config = contact_center_insights_v1.ExactMatchConfig()
        rule_group_not_shipping_or_delivery.phrase_match_rules.append(rule)
    phrase_matcher.phrase_match_rule_groups.append(rule_group_not_shipping_or_delivery)

    # Call the Insights client to create a phrase matcher.
    insights_client = contact_center_insights_v1.ContactCenterInsightsClient()
    phrase_matcher = insights_client.create_phrase_matcher(
        parent=parent, phrase_matcher=phrase_matcher
    )

    print(f"Created {phrase_matcher.name}")
    return phrase_matcher

Java

如需向 CX Insights 进行身份验证,请设置应用默认凭据。 如需了解详情,请参阅为本地开发环境设置身份验证


import com.google.cloud.contactcenterinsights.v1.ContactCenterInsightsClient;
import com.google.cloud.contactcenterinsights.v1.ExactMatchConfig;
import com.google.cloud.contactcenterinsights.v1.LocationName;
import com.google.cloud.contactcenterinsights.v1.PhraseMatchRule;
import com.google.cloud.contactcenterinsights.v1.PhraseMatchRuleConfig;
import com.google.cloud.contactcenterinsights.v1.PhraseMatchRuleGroup;
import com.google.cloud.contactcenterinsights.v1.PhraseMatcher;
import java.io.IOException;

public class CreatePhraseMatcherAllOf {

  public static void main(String[] args) throws IOException {
    // TODO(developer): Replace this variable before running the sample.
    String projectId = "my_project_id";

    createPhraseMatcherAllOf(projectId);
  }

  public static PhraseMatcher createPhraseMatcherAllOf(String projectId) throws IOException {
    // Initialize client that will be used to send requests. This client only needs to be created
    // once, and can be reused for multiple requests. After completing all of your requests, call
    // the "close" method on the client to safely clean up any remaining background resources.
    try (ContactCenterInsightsClient client = ContactCenterInsightsClient.create()) {
      // Construct a phrase matcher that matches all of its rule groups.
      PhraseMatcher.Builder phraseMatcher =
          PhraseMatcher.newBuilder()
              .setDisplayName("NON_SHIPPING_PHONE_SERVICE")
              .setTypeValue(1)
              .setActive(true);

      // Construct a rule group to match the word "PHONE" or "CELLPHONE", ignoring case sensitivity.
      PhraseMatchRuleGroup.Builder ruleGroup1 = PhraseMatchRuleGroup.newBuilder().setTypeValue(2);

      String[] words1 = {"PHONE", "CELLPHONE"};
      for (String w : words1) {
        PhraseMatchRule.Builder rule =
            PhraseMatchRule.newBuilder()
                .setQuery(w)
                .setConfig(
                    PhraseMatchRuleConfig.newBuilder()
                        .setExactMatchConfig(ExactMatchConfig.newBuilder().build())
                        .build());
        ruleGroup1.addPhraseMatchRules(rule.build());
      }
      phraseMatcher.addPhraseMatchRuleGroups(ruleGroup1.build());

      // Construct another rule group to not match the word "SHIPPING" or "DELIVERY",
      // ignoring case sensitivity.
      PhraseMatchRuleGroup.Builder ruleGroup2 = PhraseMatchRuleGroup.newBuilder().setTypeValue(1);

      String[] words2 = {"SHIPPING", "DELIVERY"};
      for (String w : words2) {
        PhraseMatchRule.Builder rule =
            PhraseMatchRule.newBuilder()
                .setQuery(w)
                .setNegated(true)
                .setConfig(
                    PhraseMatchRuleConfig.newBuilder()
                        .setExactMatchConfig(ExactMatchConfig.newBuilder().build())
                        .build());
        ruleGroup2.addPhraseMatchRules(rule.build());
      }
      phraseMatcher.addPhraseMatchRuleGroups(ruleGroup2.build());

      // Construct a parent resource.
      LocationName parent = LocationName.of(projectId, "us-central1");

      // Call the Insights client to create a phrase matcher.
      PhraseMatcher response = client.createPhraseMatcher(parent, phraseMatcher.build());
      System.out.printf("Created %s%n", response.getName());
      return response;
    }
  }
}

Node.js

如需向 CX Insights 进行身份验证,请设置应用默认凭据。 如需了解详情,请参阅为本地开发环境设置身份验证

/**
 * TODO(developer): Uncomment this variable before running the sample.
 */
// const projectId = 'my_project_id';

// Imports the Contact Center Insights client.
const {
  ContactCenterInsightsClient,
} = require('@google-cloud/contact-center-insights');

// Instantiates a client.
const client = new ContactCenterInsightsClient();

async function createPhraseMatcherAllOf() {
  const [phraseMatcher] = await client.createPhraseMatcher({
    parent: client.locationPath(projectId, 'us-central1'),
    phraseMatcher: {
      displayName: 'NON_SHIPPING_PHONE_SERVICE',
      type: 'ALL_OF',
      active: true,
      phraseMatchRuleGroups: [
        {
          type: 'ANY_OF',
          phraseMatchRules: [
            {
              query: 'PHONE',
              config: {
                exactMatchConfig: {},
              },
            },
            {
              query: 'CELLPHONE',
              config: {
                exactMatchConfig: {},
              },
            },
          ],
        },
        {
          type: 'ALL_OF',
          phraseMatchRules: [
            {
              query: 'SHIPPING',
              negated: true,
              config: {
                exactMatchConfig: {},
              },
            },
            {
              query: 'DELIVERY',
              negated: true,
              config: {
                exactMatchConfig: {},
              },
            },
          ],
        },
      ],
    },
  });
  console.info(`Created ${phraseMatcher.name}`);
}
createPhraseMatcherAllOf();