Idioma

SrgsSemanticInterpretationTag Classe

Definição

Representa uma etiqueta que contém ECMAScript e que é executada quando a regra é correspondida.

public ref class SrgsSemanticInterpretationTag : System::Speech::Recognition::SrgsGrammar::SrgsElement
public class SrgsSemanticInterpretationTag : System.Speech.Recognition.SrgsGrammar.SrgsElement
[System.Serializable]
public class SrgsSemanticInterpretationTag : System.Speech.Recognition.SrgsGrammar.SrgsElement
type SrgsSemanticInterpretationTag = class
    inherit SrgsElement
[<System.Serializable>]
type SrgsSemanticInterpretationTag = class
    inherit SrgsElement
Public Class SrgsSemanticInterpretationTag
Inherits SrgsElement
Herança
SrgsSemanticInterpretationTag
Atributos

Exemplos

O exemplo seguinte cria uma gramática para escolher as cidades para um voo. O exemplo serve SrgsSemanticInterpretationTag para atribuir um valor semântico a cada cidade, que é o código do aeroporto da cidade. O exemplo também utiliza SrgsSemanticInterpretationTag a atribuição de uma chave semântica separada para cada uma das duas referências feitas pelo SrgsRuleRef objeto nomeado cityRef ao SrgsRule objeto citiesnomeado . As chaves semânticas identificam uma cidade reconhecida como cidade de partida ou cidade de chegada do voo. O handler do SpeechRecognized evento usa as chaves para recuperar a semântica do resultado de reconhecimento.

No exemplo do código, "out" refere-se à variável Regra do que contém SrgsRule. A expressão "fora. "LeavevingFrom" refere-se à propriedade nomeada LeavingFrom da Variável Regra na regra chamada bookFlight.

A expressão "rules.flightCities" refere-se à Variável Regra na regra cuja Id é flightCities, e que é o alvo de uma referência de regra. No exemplo, a expressão "fora". LeavevingFrom=rules.flightCities;" atribui o valor da regra cujo Id é flightCities à propriedade nomeada LeavingFrom da variável de regra na regra chamada bookFlight. Consulte Conteúdo dos Resultados Semânticos, Referência de Nomes de Regras Gramaticais e Referência de Regras Gramaticais para mais informações.

using System;
using System.Speech.Recognition;
using System.Speech.Recognition.SrgsGrammar;

namespace SampleRecognition
{
  class Program
  {
    static void Main(string[] args)

    // Initialize a SpeechRecognitionEngine object.
    {
      using (SpeechRecognitionEngine recognizer =
         new SpeechRecognitionEngine(new System.Globalization.CultureInfo("en-US")))
      {

        // Create a rule for the cities, assign a semantic value to each city.
        SrgsRule cities = new SrgsRule("flightCities");
        SrgsItem chi = new SrgsItem("Chicago");
        chi.Add(new SrgsSemanticInterpretationTag("out = \"ORD\";"));
        SrgsItem bos = new SrgsItem("Boston");
        bos.Add(new SrgsSemanticInterpretationTag("out = \"BOS\";"));
        SrgsItem mia = new SrgsItem("Miami");
        mia.Add(new SrgsSemanticInterpretationTag("out = \"MIA\";"));
        SrgsItem dal = new SrgsItem("Dallas");
        dal.Add(new SrgsSemanticInterpretationTag("out = \"DFW\";"));

        SrgsOneOf airports = new SrgsOneOf(chi, bos, mia, dal);
        cities.Add(airports);
        cities.Scope = SrgsRuleScope.Private;

        // Create a rule reference to the rule for cities.
        SrgsRuleRef cityRef = new SrgsRuleRef(cities);

        // Create the root rule for the grammar.
        SrgsRule bookFlight = new SrgsRule("flightBooker");
        bookFlight.Add(new SrgsItem("I want to fly from"));
        bookFlight.Add(cityRef);
        bookFlight.Add(new SrgsSemanticInterpretationTag("out.LeavingFrom=rules.flightCities;"));
        bookFlight.Add(new SrgsItem("to"));
        bookFlight.Add(cityRef);
        bookFlight.Add(new SrgsSemanticInterpretationTag("out.GoingTo=rules.flightCities;"));
        bookFlight.Scope = SrgsRuleScope.Public;

        // Initialize the SrgsDocument, set the root rule, add rules to the collection.
        SrgsDocument itinerary = new SrgsDocument(bookFlight);
        itinerary.Rules.Add(cities);

        // Create a Grammar object and load it to the recognizer.
        Grammar g = new Grammar(itinerary);
        g.Name = ("City Chooser");
        recognizer.LoadGrammarAsync(g);

        // Configure recognizer input.
        recognizer.SetInputToDefaultAudioDevice();

        // Attach a handler for the SpeechRecognized event.
        recognizer.SpeechRecognized +=
          new EventHandler<SpeechRecognizedEventArgs>(recognizer_SpeechRecognized);

        // Start recognition.
        recognizer.RecognizeAsync();
        Console.WriteLine("Starting asynchronous recognition...");

        // Keep the console window open.
        Console.ReadLine();
      }
    }

    // Write to the console the text and the semantics from the recognition result.
    static void recognizer_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
    {
      Console.WriteLine("Speech recognized: " + e.Result.Text);
      Console.WriteLine();
      Console.WriteLine("Semantic results:");
      Console.WriteLine("  The departure city is: " + e.Result.Semantics["LeavingFrom"].Value);
      Console.WriteLine("  The arrival city is: " + e.Result.Semantics["GoingTo"].Value);
    }
  }
}

Segue-se a forma XML da gramática gerada pelo código no exemplo acima.

<?xml version="1.0" encoding="utf-8"?>
<grammar xml:lang="en-US" root="flightBooker" tag-format="semantics/1.0"
version="1.0" xmlns="http://www.w3.org/2001/06/grammar">

  <rule id="flightBooker" scope="public">
    <item> I want to fly from </item>
    <ruleref uri="#flightCities" />
    <tag> out.LeavingFrom=rules.flightCities; </tag>
    <item> to </item>
    <ruleref uri="#flightCities" />
    <tag> out.GoingTo=rules.flightCities; </tag>
  </rule>

  <rule id="flightCities" scope="private">
    <one-of>
      <item> Chicago <tag> out="ORD"; </tag></item>
      <item> Boston <tag> out="BOS"; </tag></item>
      <item> Miami <tag> out="MIA"; </tag></item>
      <item> Dallas <tag> out="DFW"; </tag></item>
    </one-of>
  </rule>

</grammar>

Observações

O formato semântico padrão para o System.Speech está em conformidade com a Versão 1.0 do W3C Semantic Interpretation for Speech Recognition (SISR), onde o formato para tag elementos que contêm script é semantics/1.0. Deve especificar o script para SrgsSemanticInterpretationTag objetos que utilizam este formato. Na sintaxe de semantics/1.0:

  • A variável Regra do elemento de regra que contém é identificada por "out".
  • O nome do objeto que tem acesso à variável Regra dos elementos de regra fora do elemento de regra que contém é identificado por "regras".
  • O resultado da última regra referenciada que corresponde à enunciação pode ser representado por "rules.latest()".

Também pode associar um valor semântico a uma frase numa gramática sem usar script usando o SrgsNameValueTag objeto.

Construtores

Nome Descrição
SrgsSemanticInterpretationTag()

Cria uma instância da SrgsSemanticInterpretationTag classe.

SrgsSemanticInterpretationTag(String)

Cria uma instância da SrgsSemanticInterpretationTag classe, especificando o conteúdo do script da etiqueta.

Propriedades

Nome Descrição
Script

Obtém ou define o ECMAScript para a etiqueta.

Métodos

Nome Descrição
CreateObjRef(Type)

Cria um objeto que contém toda a informação relevante necessária para gerar um proxy usado para comunicar com um objeto remoto.

(Herdado de MarshalByRefObject)
Equals(Object)

Determina se o objeto especificado é igual ao objeto atual.

(Herdado de Object)
GetHashCode()

Serve como função de hash predefinida.

(Herdado de Object)
GetLifetimeService()
Obsoleto.

Recupera o objeto de serviço de tempo de vida atual que controla a política de vida útil neste caso.

(Herdado de MarshalByRefObject)
GetType()

Obtém o Type da instância atual.

(Herdado de Object)
InitializeLifetimeService()
Obsoleto.

Obtém-se um objeto de serviço vitalício para controlar a apólice vitalícia neste caso.

(Herdado de MarshalByRefObject)
MemberwiseClone()

Cria uma cópia superficial do atual Object.

(Herdado de Object)
MemberwiseClone(Boolean)

Cria uma cópia superficial do objeto atual MarshalByRefObject .

(Herdado de MarshalByRefObject)
ToString()

Devolve uma cadeia que representa o objeto atual.

(Herdado de Object)

Aplica-se a