Catalog

class elg.catalog.Catalog(domain: str = 'live')

Class to use the ELG search API. Browse the ELG catalogue using Python.

Examples:

from elg import Catalog

# First you have to init a catalog object.
catalog = Catalog()

# Then you can use the search method to search for resources. This method returns a list of Entity which can be displayed individually.
# For example, we can search for a Machine Translation service for English and French.
results = catalog.search(
    resource = "Tool/Service", # "Corpus", "Lexical/Conceptual resource" or "Language description"
    function = "Machine Translation", # function should be pass only if resource is set to "Tool/Service"
    languages = ["en", "fr"], # string or list if multiple languages
    limit = 100,
)
print(f"Machine Translation service for English and French:\n{results[0]}")

# Another example can be a German NER corpora.
results = catalog.search(
    resource = "Corpus", # "Corpus", "Lexical/Conceptual resource" or "Language description"
    languages = ["German"], # string or list if multiple languages
    search="ner",
    limit = 100,
)
print(f"German corpus for NER:\n{results[0]}")

# You can init a service from an Entity.

# We can use the catalog to search a Named Entity Recognizer for French and init a Service with the returned Entity.
results = catalog.search(
    resource = "Tool/Service",
    function = "Named Entity Recognition",
    languages = ["fr"],
    limit = 1,
)
entity = results[0]
print(entity)

from elg import Service

lt = Service.from_entity(entity=entity)
result = lt("Jean Dupond vit à Paris.")
print(f"\n{result}")
search(entity: str = 'LanguageResource', search: Optional[str] = None, resource: Optional[str] = None, function: Optional[str] = None, languages: Optional[Union[str, list]] = None, license: Optional[str] = None, limit: int = 100)

Generator to iterate through search results via the API.

Parameters
  • entity (str, optional) – type of the entity to search. Can be ‘LanguageResource’, ‘Organization’, or ‘Project’. Defaults to “LanguageResource”.

  • search (str, optional) – terms to use for the search request. Defaults to None.

  • resource (str, optional) – type of the language resource. Only used when the entity is set to ‘LanguageResource’. Can be ‘Tool/Service’, ‘Lexical/Conceptual resource’, ‘Corpus’, or ‘Language description’. Defaults to None.

  • function (str, optional) – type of the function of the service. Only used when resource set to ‘Tool/Service’. Defaults to None.

  • languages (Union[str, list], optional) – language filter for the search request. Can be a string or a list of string. If it is a list of strings, the results of the request will match will all the languages and not one among all. The full name or the ISO639 code of the language can be used. Defaults to None.

  • license (str, optional) – license filter. Defaults to None.

  • limit (int, optional) – limit number of results. Defaults to 100.

Yields

elg.Entity – search results one entity at a time.

Examples:

results = [ r for r in catalog.search(
    resource = "Tool/Service",
    function = "Machine Translation",
    languages = ["en", "fr"],
    limit = 100,
)]
results = [ r for r in catalog.search(
    resource = "Corpus",
    languages = ["German"],
    search="ner",
    limit = 100,
)]

Method to search resources interactivly. Warn: not well coded and tested.