SrgsSemanticInterpretationTag Classe

Definição

Representa uma marca que contém ECMAScript que é executado quando a regra é correspondida.

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

Exemplos

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

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

A expressão "rules.flightCities" refere-se à Variável de Regra na regra cujo Id é flightCitiese que é o destino de uma referência de regra. No exemplo, a expressão "out. LeavingFrom=rules.flightCities;" atribui o valor da regra cuja Id propriedade é flightCities chamada LeavingFrom de Variável de Regra na regra chamada bookFlight. Consulte Conteúdo de resultados semânticos, Referência de nome de regra gramatical e Referência de regra gramatical para obter 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);  
    }  
  }  
}  

Veja a seguir 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>  

Comentários

O formato semântico padrão para System.Speech está em conformidade com a Interpretação Semântica do W3C para Reconhecimento de Fala (SISR) versão 1.0, em que o formato para tag elementos que contêm script é semantics/1.0. Você deve especificar o script para SrgsSemanticInterpretationTag objetos usando esse formato. Na sintaxe de semantics/1.0:

  • A Variável de Regra do elemento de regra que contém é identificada por "out".

  • O nome do objeto que tem acesso à Variável de Regra de elementos de regra fora do elemento de regra que contém é identificado por "regras".

  • O resultado da regra referenciada mais recente que corresponde ao enunciado pode ser representado por "rules.latest()".

Você também pode associar um valor semântico a uma frase em uma gramática sem usar script, usando o SrgsNameValueTag objeto .

Construtores

SrgsSemanticInterpretationTag()

Cria uma instância de SrgsSemanticInterpretationTag classe.

SrgsSemanticInterpretationTag(String)

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

Propriedades

Script

Obtém ou define o ECMAScript para a marca.

Métodos

CreateObjRef(Type)

Cria um objeto que contém todas as informações relevantes necessárias para gerar um proxy usado para se 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 a função de hash padrão.

(Herdado de Object)
GetLifetimeService()
Obsoleto.

Recupera o objeto de serviço de tempo de vida atual que controla a política de ciclo de vida para esta instância.

(Herdado de MarshalByRefObject)
GetType()

Obtém o Type da instância atual.

(Herdado de Object)
InitializeLifetimeService()
Obsoleto.

Obtém um objeto de serviço de tempo de vida para controlar a política de tempo de vida para essa instância.

(Herdado de MarshalByRefObject)
MemberwiseClone()

Cria uma cópia superficial do Object atual.

(Herdado de Object)
MemberwiseClone(Boolean)

Cria uma cópia superficial do objeto MarshalByRefObject atual.

(Herdado de MarshalByRefObject)
ToString()

Retorna uma cadeia de caracteres que representa o objeto atual.

(Herdado de Object)

Aplica-se a