Search in sources :

Example 6 with Token

use of com.google.cloud.language.v1.Token in project bayou by capergroup.

the class EvidenceLLexerTests method testLexColon.

@Test
public void testLexColon() {
    EvidenceLLexer lexer = makeLexer();
    Iterator<Token> tokens = lexer.lex(":").iterator();
    Assert.assertTrue(tokens.hasNext());
    Token token = tokens.next();
    Assert.assertEquals(":", token.getLexeme());
    Assert.assertTrue(token.getType() instanceof TokenTypeColon);
}
Also used : TokenTypeColon(edu.rice.cs.caper.bayou.core.lexer.evidencel._1_0.TokenTypeColon) Token(edu.rice.cs.caper.bayou.core.lexer.evidencel._1_0.Token) EvidenceLLexer(edu.rice.cs.caper.bayou.core.lexer.evidencel._1_0.EvidenceLLexer) Test(org.junit.Test)

Example 7 with Token

use of com.google.cloud.language.v1.Token in project bayou by capergroup.

the class EvidenceLLexerTests method testLexIdents.

@Test
public void testLexIdents() {
    EvidenceLLexer lexer = makeLexer();
    Iterator<Token> tokens = lexer.lex("ident1 ident2").iterator();
    Assert.assertTrue(tokens.hasNext());
    Token token = tokens.next();
    Assert.assertEquals("ident1", token.getLexeme());
    Assert.assertTrue(token.getType() instanceof TokenTypeIdentifier);
    token = tokens.next();
    Assert.assertEquals("ident2", token.getLexeme());
    Assert.assertTrue(token.getType() instanceof TokenTypeIdentifier);
}
Also used : TokenTypeIdentifier(edu.rice.cs.caper.bayou.core.lexer.evidencel._1_0.TokenTypeIdentifier) Token(edu.rice.cs.caper.bayou.core.lexer.evidencel._1_0.Token) EvidenceLLexer(edu.rice.cs.caper.bayou.core.lexer.evidencel._1_0.EvidenceLLexer) Test(org.junit.Test)

Example 8 with Token

use of com.google.cloud.language.v1.Token in project bayou by capergroup.

the class EvidenceLLexerTests method testLexIdent.

@Test
public void testLexIdent() {
    EvidenceLLexer lexer = makeLexer();
    Iterator<Token> tokens = lexer.lex("ident").iterator();
    Assert.assertTrue(tokens.hasNext());
    Token token = tokens.next();
    Assert.assertEquals("ident", token.getLexeme());
    Assert.assertTrue(token.getType() instanceof TokenTypeIdentifier);
}
Also used : TokenTypeIdentifier(edu.rice.cs.caper.bayou.core.lexer.evidencel._1_0.TokenTypeIdentifier) Token(edu.rice.cs.caper.bayou.core.lexer.evidencel._1_0.Token) EvidenceLLexer(edu.rice.cs.caper.bayou.core.lexer.evidencel._1_0.EvidenceLLexer) Test(org.junit.Test)

Example 9 with Token

use of com.google.cloud.language.v1.Token in project bayou by capergroup.

the class EvidenceLLexerTests method testLexEmpty.

@Test
public void testLexEmpty() {
    EvidenceLLexer lexer = makeLexer();
    Iterator<Token> tokens = lexer.lex("").iterator();
    Assert.assertFalse(tokens.hasNext());
}
Also used : Token(edu.rice.cs.caper.bayou.core.lexer.evidencel._1_0.Token) EvidenceLLexer(edu.rice.cs.caper.bayou.core.lexer.evidencel._1_0.EvidenceLLexer) Test(org.junit.Test)

Example 10 with Token

use of com.google.cloud.language.v1.Token in project java-docs-samples by GoogleCloudPlatform.

the class Analyze method analyzeSyntaxText.

/**
 * from the string {@code text}.
 */
public static List<Token> analyzeSyntaxText(String text) throws Exception {
    // Instantiate the Language client com.google.cloud.language.v1.LanguageServiceClient
    try (LanguageServiceClient language = LanguageServiceClient.create()) {
        Document doc = Document.newBuilder().setContent(text).setType(Type.PLAIN_TEXT).build();
        AnalyzeSyntaxRequest request = AnalyzeSyntaxRequest.newBuilder().setDocument(doc).setEncodingType(EncodingType.UTF16).build();
        // analyze the syntax in the given text
        AnalyzeSyntaxResponse response = language.analyzeSyntax(request);
        // print the response
        for (Token token : response.getTokensList()) {
            System.out.printf("\tText: %s\n", token.getText().getContent());
            System.out.printf("\tBeginOffset: %d\n", token.getText().getBeginOffset());
            System.out.printf("Lemma: %s\n", token.getLemma());
            System.out.printf("PartOfSpeechTag: %s\n", token.getPartOfSpeech().getTag());
            System.out.printf("\tAspect: %s\n", token.getPartOfSpeech().getAspect());
            System.out.printf("\tCase: %s\n", token.getPartOfSpeech().getCase());
            System.out.printf("\tForm: %s\n", token.getPartOfSpeech().getForm());
            System.out.printf("\tGender: %s\n", token.getPartOfSpeech().getGender());
            System.out.printf("\tMood: %s\n", token.getPartOfSpeech().getMood());
            System.out.printf("\tNumber: %s\n", token.getPartOfSpeech().getNumber());
            System.out.printf("\tPerson: %s\n", token.getPartOfSpeech().getPerson());
            System.out.printf("\tProper: %s\n", token.getPartOfSpeech().getProper());
            System.out.printf("\tReciprocity: %s\n", token.getPartOfSpeech().getReciprocity());
            System.out.printf("\tTense: %s\n", token.getPartOfSpeech().getTense());
            System.out.printf("\tVoice: %s\n", token.getPartOfSpeech().getVoice());
            System.out.println("DependencyEdge");
            System.out.printf("\tHeadTokenIndex: %d\n", token.getDependencyEdge().getHeadTokenIndex());
            System.out.printf("\tLabel: %s\n\n", token.getDependencyEdge().getLabel());
        }
        return response.getTokensList();
    }
// [END analyze_syntax_text]
}
Also used : LanguageServiceClient(com.google.cloud.language.v1.LanguageServiceClient) AnalyzeSyntaxRequest(com.google.cloud.language.v1.AnalyzeSyntaxRequest) Token(com.google.cloud.language.v1.Token) Document(com.google.cloud.language.v1.Document) AnalyzeSyntaxResponse(com.google.cloud.language.v1.AnalyzeSyntaxResponse)

Aggregations

Token (edu.rice.cs.caper.bayou.core.lexer.evidencel._1_0.Token)7 EvidenceLLexer (edu.rice.cs.caper.bayou.core.lexer.evidencel._1_0.EvidenceLLexer)6 Test (org.junit.Test)6 TokenTypeIdentifier (edu.rice.cs.caper.bayou.core.lexer.evidencel._1_0.TokenTypeIdentifier)4 TokenTypeColon (edu.rice.cs.caper.bayou.core.lexer.evidencel._1_0.TokenTypeColon)3 Token (org.openstack4j.model.identity.v3.Token)3 AnalyzeSyntaxRequest (com.google.cloud.language.v1.AnalyzeSyntaxRequest)2 AnalyzeSyntaxResponse (com.google.cloud.language.v1.AnalyzeSyntaxResponse)2 Document (com.google.cloud.language.v1.Document)2 LanguageServiceClient (com.google.cloud.language.v1.LanguageServiceClient)2 Token (com.google.cloud.language.v1.Token)2 CloudConnectorException (com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException)2 Access (org.openstack4j.model.identity.v2.Access)2 Token (com.lingtuan.firefly.custom.contact.HanziToPinyin3.Token)1 HashSet (java.util.HashSet)1 Access (org.openstack.docs.identity.api.v2.Access)1 Token (org.openstack.docs.identity.api.v2.Token)1 KeystoneAuthenticationToken (org.openstack.keystone.auth.client.KeystoneAuthenticationToken)1 Endpoint (org.openstack4j.model.identity.v3.Endpoint)1 Service (org.openstack4j.model.identity.v3.Service)1