textaDetectTopicsStatus: Retrieves the status of a topic detection operation submitted...

Description Usage Arguments Value Author(s) Examples

View source: R/textaDetectTopicsStatus.R

Description

This function retrieves the status of an asynchronous topic detection operation previously submitted for processing. If the operation has reached a 'Succeeded' state, this function will also return the results.

Internally, this function invokes the Microsoft Cognitive Services Text Analytics REST API documented at https://www.microsoft.com/cognitive-services/en-us/text-analytics/documentation.

You MUST have a valid Microsoft Cognitive Services account and an API key for this function to work properly. See https://www.microsoft.com/cognitive-services/en-us/pricing for details.

Usage

1
textaDetectTopicsStatus(operation, verbose = FALSE)

Arguments

operation

(textatopics) textatopics S3 object returned by the original call to textaDetectTopics.

verbose

(logical) If set to TRUE, print poll status to stdout.

Value

An S3 object of the class textatopics with the results of the topic detection operation. See textatopics for details.

Author(s)

Phil Ferriere [email protected]

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
## Not run: 
 load("./data/yelpChineseRestaurantReviews.rda")
 set.seed(1234)
 documents <- sample(yelpChReviews$text, 1000)

 tryCatch({

   # Start async topic detection
   operation <- textaDetectTopics(
     documents,                  # At least 100 docs/sentences
     stopWords = NULL,           # Stop word list (optional)
     topicsToExclude = NULL,     # Topics to exclude (optional)
     minDocumentsPerWord = NULL, # Threshold to exclude rare topics (optional)
     maxDocumentsPerWord = NULL, # Threshold to exclude ubiquitous topics (optional)
     resultsPollInterval = 0L    # Poll interval (in s, default: 30s, use 0L for async)
   )

   # Poll the servers until the work completes or until we time out
   resultsPollInterval <- 60L
   resultsTimeout <- 1200L
   startTime <- Sys.time()
   endTime <- startTime + resultsTimeout

   while (Sys.time() <= endTime) {
     sleepTime <- startTime + resultsPollInterval - Sys.time()
     if (sleepTime > 0)
       Sys.sleep(sleepTime)
     startTime <- Sys.time()

     # Poll for results
     topics <- textaDetectTopicsStatus(operation)
     if (topics$status != "NotStarted" && topics$status != "Running")
       break;
   }

   # Class and structure of topics
   class(topics)
   #> [1] "textatopics"

   str(topics, max.level = 1)
   #> List of 8
   #> $ status          : chr "Succeeded"
   #> $ operationId     : chr "30334a3e1e28406a80566bb76ff04884"
   #> $ operationType   : chr "topics"
   #> $ documents       :'data.frame':  1000 obs. of  2 variables:
   #> $ topics          :'data.frame':  71 obs. of  3 variables:
   #> $ topicAssignments:'data.frame':  502 obs. of  3 variables:
   #> $ json            : chr "{\"status\":\"Succeeded\",\"createdDateTime\": __truncated__ }
   #> $ request         :List of 7
   #> ..- attr(*, "class")= chr "request"
   #> - attr(*, "class")= chr "textatopics"

   # Print results
   topics
   #> textatopics [https://westus.api.cognitive.microsoft.com/text/analytics/ __truncated__ ]
   #> status: Succeeded
   #> operationId: 30334a3e1e28406a80566bb76ff04884
   #> operationType: topics
   #> topics (first 20):
   #> ------------------------
   #>    keyPhrase      score
   #> ---------------- -------
   #>     portions       35
   #>   noodle soup      30
   #>    vegetables      20
   #>       tofu         19
   #>      garlic        17
   #>     Eggplant       15
   #>       Pad          15
   #>      combo         13
   #> Beef Noodle Soup   13
   #>      House         12
   #>      entree        12
   #>     wontons        12
   #>     Pei Wei        12
   #>  mongolian beef    11
   #>       crab         11
   #>      Panda         11
   #>       bean         10
   #>    dumplings        9
   #>     veggies         9
   #>      decor          9
   #> ------------------------

 }, error = function(err) {

   # Print error
   geterrmessage()

 })

## End(Not run)

mscstexta4r documentation built on May 29, 2017, 12:03 p.m.