Beispiel #1
0
# Demonstrates the use of the self-documentation resource 'taxonomies' of the expert.ai (Cloud based) Natural Language API

from expertai.nlapi.cloud.client import ExpertAiClient

client = ExpertAiClient()

output = client.taxonomies()

print("Taxonomies:\n")

for taxonomy in output.taxonomies:
    print(taxonomy.name)
    print("\tLanguages:")
    for language in taxonomy.languages:
        print("\t\t{0}".format(language.code))
Beispiel #2
0
    def test_a_taxonomies_request_is_executed(self):
        """
        ...then verify that whole flow works as expected
        """
        response_json = {
            "success":
            True,
            "taxonomies": [{
                "description":
                "The iptc document classification resource classifies texts based on the IPTC Media Topics taxonomy",
                "languages": [{
                    "code": "en",
                    "name": "English"
                }, {
                    "code": "es",
                    "name": "Spanish"
                }, {
                    "code": "fr",
                    "name": "French"
                }, {
                    "code": "de",
                    "name": "German"
                }, {
                    "code": "it",
                    "name": "Italian"
                }],
                "name":
                "iptc"
            }, {
                "contract":
                "https://github.com/therealexpertai/nlapi-openapi-specification/blob/master/geotax.yaml",
                "description":
                "The geotax document classification resource recognizes geographic places cited in the text and returns corresponding countries' names. In addition, when requested with a specific query-string parameter, it returns extra-data containing equivalent GeoJSON objects. See the specific OpenAPI document (https://github.com/therealexpertai/nlapi-openapi-specification/blob/master/geotax.yaml) for information about the way to obtain and interpret GeoJSON data.",
                "languages": [{
                    "code": "en",
                    "name": "English"
                }, {
                    "code": "es",
                    "name": "Spanish"
                }, {
                    "code": "fr",
                    "name": "French"
                }, {
                    "code": "de",
                    "name": "German"
                }, {
                    "code": "it",
                    "name": "Italian"
                }],
                "name":
                "geotax"
            }]
        }
        response = MagicMock()
        response.status_code = 200
        response.ok = True
        response.json.return_value = response_json

        self.patched_get.return_value = response
        client = ExpertAiClient()
        dm = client.taxonomies()
        self.assertEqual(dm.taxonomies[1].name, "geotax")
        self.assertEqual(dm.taxonomies[0].languages[2].code, "fr")