{"_id":"584aeea99588370f00608a8b","project":"559ae8ec7ae7f80d0096d813","user":"55a6a2fb51457325000e4e3d","version":{"_id":"584aeea89588370f00608a3b","project":"559ae8ec7ae7f80d0096d813","__v":1,"createdAt":"2016-12-09T17:49:28.502Z","releaseDate":"2016-12-09T17:49:28.502Z","categories":["584aeea89588370f00608a3c","584aeea89588370f00608a3d","584aeea89588370f00608a3e","584aeea89588370f00608a3f","584aeea89588370f00608a40","584aeea89588370f00608a41","584aeea89588370f00608a42","584aeea89588370f00608a43","584aeea89588370f00608a44","584aeea89588370f00608a45","584aeea89588370f00608a46","584aeea89588370f00608a47","584aeea89588370f00608a48","584aeea89588370f00608a49","584aeea89588370f00608a4a","584aeea89588370f00608a4b","584aeea89588370f00608a4c","584aeea89588370f00608a4d","584aeea89588370f00608a4e","584aeea89588370f00608a4f"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"","version_clean":"4.2.3","version":"4.2.3"},"__v":0,"category":{"_id":"584aeea89588370f00608a40","version":"584aeea89588370f00608a3b","__v":0,"project":"559ae8ec7ae7f80d0096d813","sync":{"url":"","isSync":false},"reference":false,"createdAt":"2015-07-07T21:23:18.455Z","from_sync":false,"order":4,"slug":"get-started","title":"Get Started"},"parentDoc":null,"updates":[],"next":{"pages":[],"description":""},"createdAt":"2015-09-15T18:09:38.366Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":22,"body":"Now that you have your key and secret, you can send documents to Semantria. Since Semantria is asynchronous, you will need to request them as well. Here is a simple snippet to submit three documents for analysis and retrieve them. A more worked out example that handles errors and prints results is shown in our Quick Start Guides.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"import semantria, time, uuid\\n\\n#some sample text\\ninitialTexts = [\\n    \\\"Lisa - there's 2 Skinny cow coupons available $5 skinny cow ice cream coupons on special k boxes and Printable FPC from facebook - a teeny tiny cup of ice cream. I printed off 2 (1 from my account and 1 from dh's). I couldn't find them instore and i'm not going to walmart before the 19th. Oh well sounds like i'm not missing much ...lol\\\",\\n    \\\"In Lake Louise - a guided walk for the family with Great Divide Nature Tours  rent a canoe on Lake Louise or Moraine Lake  go for a hike to the Lake Agnes Tea House. In between Lake Louise and Banff - visit Marble Canyon or Johnson Canyon or both for family friendly short walks. In Banff  a picnic at Johnson Lake  rent a boat at Lake Minnewanka  hike up Tunnel Mountain  walk to the Bow Falls and the Fairmont Banff Springs Hotel  visit the Banff Park Museum. The \\\\\\\"must-do\\\\\\\" in Banff is a visit to the Banff Gondola and some time spent on Banff Avenue - think candy shops and ice cream. Have a Fanta while you're there.\\\",\\n    \\\"On this day in 1786 - In New York City  commercial ice cream was manufactured for the first time.\\\"\\n]\\nfor text in initialTexts:\\n   doc = {\\\"id\\\": str(uuid.uuid4()).replace(\\\"-\\\", \\\"\\\"), \\\"text\\\": text}\\n\\nsession = semantria.Session(key, secret)\\n#queue a batch of documents\\nsession.queueBatch(initialTexts)\\n#keep track of how many we sent\\nnumber_of_docs = len(initialTexts)\\nresults = []\\n#keep polling for results until we got everything back\\nwhile len(results) < number_of_docs:\\n  time.sleep(3)\\n  status = session.getProcessedDocuments()\\n  if isinstance(status, list):\\n        for object_ in status:\\n            results.append(object_)\\n          \",\n      \"language\": \"python\"\n    },\n    {\n      \"code\": \"using System;\\nusing System.Collections.Generic;\\nusing System.Linq;\\n\\nusing Semantria.Com;\\n\\nnamespace Quickstart\\n{\\n    class Program\\n    {\\n        static void Main(string[] args)\\n        {\\n\\n            // Replace with your API key and secret\\n            string API_KEY = \\\"\\\";\\n            string API_SECRET = \\\"\\\";\\n            \\n            // Some sample text\\n            List<String> myText = new List<string>();\\n            myText.Add(\\\"Lisa - there's 2 Skinny cow coupons available $5 skinny cow ice cream coupons on special k boxes and Printable FPC from facebook - a teeny tiny cup of ice cream. I printed off 2 (1 from my account and 1 from dh's). I couldn't find them instore and i'm not going to walmart before the 19th. Oh well sounds like i'm not missing much ...lol\\\");\\n            myText.Add(\\\"In Lake Louise - a guided walk for the family with Great Divide Nature Tours  rent a canoe on Lake Louise or Moraine Lake  go for a hike to the Lake Agnes Tea House. In between Lake Louise and Banff - visit Marble Canyon or Johnson Canyon or both for family friendly short walks. In Banff  a picnic at Johnson Lake  rent a boat at Lake Minnewanka  hike up Tunnel Mountain  walk to the Bow Falls and the Fairmont Banff Springs Hotel  visit the Banff Park Museum. The \\\\\\\"must-do\\\\\\\" in Banff is a visit to the Banff Gondola and some time spent on Banff Avenue - think candy shops and ice cream. Have a Fanta while you're there.\\\");\\n            myText.Add(\\\"On this day in 1786 - In New York City  commercial ice cream was manufactured for the first time.\\\");\\n\\n            // Instantiate a Semantria session\\n            ISerializer serializer = new Semantria.Com.Serializers.JsonSerializer();\\n            Semantria.Com.Session mySession = Semantria.Com.Session.CreateSession(API_KEY, API_SECRET, serializer);\\n\\n            // Generate Semantria Document list to send for processing\\n            List<Semantria.Com.Mapping.Document> myOutgoingDocuments = new List<Semantria.Com.Mapping.Document>(myText.Count);\\n            foreach (string aText in myText)\\n            {\\n                string DocId = Guid.NewGuid().ToString();\\n                Semantria.Com.Mapping.Document aDocument = new Semantria.Com.Mapping.Document(){Id = DocId, Text = aText};\\n                myOutgoingDocuments.Add(aDocument);\\n            }\\n\\n            // Queue a batch of documents\\n            mySession.QueueBatchOfDocuments(myOutgoingDocuments);\\n            \\n            // Prepare a list for results\\n            List<Semantria.Com.Mapping.Output.DocAnalyticData> myResults = new List<Semantria.Com.Mapping.Output.DocAnalyticData>();\\n            foreach (Semantria.Com.Mapping.Document aDocument in myOutgoingDocuments)\\n            {\\n                Semantria.Com.Mapping.Output.DocAnalyticData aResult = new Semantria.Com.Mapping.Output.DocAnalyticData();\\n                aResult.Id = aDocument.Id;\\n                aResult.Status = Semantria.Com.TaskStatus.QUEUED;\\n                myResults.Add(aResult);\\n            }\\n\\n            // Poll for results until we've got results for everything we sent\\n            while (myResults.Any(item => item.Status == TaskStatus.QUEUED))\\n            {\\n                // Wait 3 seconds in between each poll for results\\n                System.Threading.Thread.Sleep(3000);\\n\\n                // Check for results\\n                IList<Semantria.Com.Mapping.Output.DocAnalyticData> myIncomingResults = mySession.GetProcessedDocuments();\\n                foreach (Semantria.Com.Mapping.Output.DocAnalyticData aIncomingResult in myIncomingResults)\\n                {\\n                    for (int i = 0; i < myResults.Count; i++)\\n                    {\\n                        if (myResults[i].Id == aIncomingResult.Id)\\n                        {\\n                            myResults[i] = aIncomingResult;\\n                            break;\\n                        }\\n                    }\\n                }\\n            }\\n        }\\n    }\\n}\\n\",\n      \"language\": \"csharp\"\n    }\n  ]\n}\n[/block]","excerpt":"","slug":"send-some-documents","type":"basic","title":"Process some documents"}

Process some documents


Now that you have your key and secret, you can send documents to Semantria. Since Semantria is asynchronous, you will need to request them as well. Here is a simple snippet to submit three documents for analysis and retrieve them. A more worked out example that handles errors and prints results is shown in our Quick Start Guides. [block:code] { "codes": [ { "code": "import semantria, time, uuid\n\n#some sample text\ninitialTexts = [\n \"Lisa - there's 2 Skinny cow coupons available $5 skinny cow ice cream coupons on special k boxes and Printable FPC from facebook - a teeny tiny cup of ice cream. I printed off 2 (1 from my account and 1 from dh's). I couldn't find them instore and i'm not going to walmart before the 19th. Oh well sounds like i'm not missing much ...lol\",\n \"In Lake Louise - a guided walk for the family with Great Divide Nature Tours rent a canoe on Lake Louise or Moraine Lake go for a hike to the Lake Agnes Tea House. In between Lake Louise and Banff - visit Marble Canyon or Johnson Canyon or both for family friendly short walks. In Banff a picnic at Johnson Lake rent a boat at Lake Minnewanka hike up Tunnel Mountain walk to the Bow Falls and the Fairmont Banff Springs Hotel visit the Banff Park Museum. The \\\"must-do\\\" in Banff is a visit to the Banff Gondola and some time spent on Banff Avenue - think candy shops and ice cream. Have a Fanta while you're there.\",\n \"On this day in 1786 - In New York City commercial ice cream was manufactured for the first time.\"\n]\nfor text in initialTexts:\n doc = {\"id\": str(uuid.uuid4()).replace(\"-\", \"\"), \"text\": text}\n\nsession = semantria.Session(key, secret)\n#queue a batch of documents\nsession.queueBatch(initialTexts)\n#keep track of how many we sent\nnumber_of_docs = len(initialTexts)\nresults = []\n#keep polling for results until we got everything back\nwhile len(results) < number_of_docs:\n time.sleep(3)\n status = session.getProcessedDocuments()\n if isinstance(status, list):\n for object_ in status:\n results.append(object_)\n ", "language": "python" }, { "code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\n\nusing Semantria.Com;\n\nnamespace Quickstart\n{\n class Program\n {\n static void Main(string[] args)\n {\n\n // Replace with your API key and secret\n string API_KEY = \"\";\n string API_SECRET = \"\";\n \n // Some sample text\n List<String> myText = new List<string>();\n myText.Add(\"Lisa - there's 2 Skinny cow coupons available $5 skinny cow ice cream coupons on special k boxes and Printable FPC from facebook - a teeny tiny cup of ice cream. I printed off 2 (1 from my account and 1 from dh's). I couldn't find them instore and i'm not going to walmart before the 19th. Oh well sounds like i'm not missing much ...lol\");\n myText.Add(\"In Lake Louise - a guided walk for the family with Great Divide Nature Tours rent a canoe on Lake Louise or Moraine Lake go for a hike to the Lake Agnes Tea House. In between Lake Louise and Banff - visit Marble Canyon or Johnson Canyon or both for family friendly short walks. In Banff a picnic at Johnson Lake rent a boat at Lake Minnewanka hike up Tunnel Mountain walk to the Bow Falls and the Fairmont Banff Springs Hotel visit the Banff Park Museum. The \\\"must-do\\\" in Banff is a visit to the Banff Gondola and some time spent on Banff Avenue - think candy shops and ice cream. Have a Fanta while you're there.\");\n myText.Add(\"On this day in 1786 - In New York City commercial ice cream was manufactured for the first time.\");\n\n // Instantiate a Semantria session\n ISerializer serializer = new Semantria.Com.Serializers.JsonSerializer();\n Semantria.Com.Session mySession = Semantria.Com.Session.CreateSession(API_KEY, API_SECRET, serializer);\n\n // Generate Semantria Document list to send for processing\n List<Semantria.Com.Mapping.Document> myOutgoingDocuments = new List<Semantria.Com.Mapping.Document>(myText.Count);\n foreach (string aText in myText)\n {\n string DocId = Guid.NewGuid().ToString();\n Semantria.Com.Mapping.Document aDocument = new Semantria.Com.Mapping.Document(){Id = DocId, Text = aText};\n myOutgoingDocuments.Add(aDocument);\n }\n\n // Queue a batch of documents\n mySession.QueueBatchOfDocuments(myOutgoingDocuments);\n \n // Prepare a list for results\n List<Semantria.Com.Mapping.Output.DocAnalyticData> myResults = new List<Semantria.Com.Mapping.Output.DocAnalyticData>();\n foreach (Semantria.Com.Mapping.Document aDocument in myOutgoingDocuments)\n {\n Semantria.Com.Mapping.Output.DocAnalyticData aResult = new Semantria.Com.Mapping.Output.DocAnalyticData();\n aResult.Id = aDocument.Id;\n aResult.Status = Semantria.Com.TaskStatus.QUEUED;\n myResults.Add(aResult);\n }\n\n // Poll for results until we've got results for everything we sent\n while (myResults.Any(item => item.Status == TaskStatus.QUEUED))\n {\n // Wait 3 seconds in between each poll for results\n System.Threading.Thread.Sleep(3000);\n\n // Check for results\n IList<Semantria.Com.Mapping.Output.DocAnalyticData> myIncomingResults = mySession.GetProcessedDocuments();\n foreach (Semantria.Com.Mapping.Output.DocAnalyticData aIncomingResult in myIncomingResults)\n {\n for (int i = 0; i < myResults.Count; i++)\n {\n if (myResults[i].Id == aIncomingResult.Id)\n {\n myResults[i] = aIncomingResult;\n break;\n }\n }\n }\n }\n }\n }\n}\n", "language": "csharp" } ] } [/block]