wn.project

Wordnet and ILI Packages and Collections

wn.project.get_project(*, project: str | None = None, path: str | Path | None = None) Project

Return the Project object for project or path.

The project argument is a project specifier and will look in the download cache for the project data. If the project has not been downloaded and cached, an error will be raised.

The path argument looks for project data at the given path. It can point to a resource file, a package directory, or a collection directory. Unlike iterpackages(), this function does not iterate over packages within a collection, and instead the Collection object is returned.

Note

If the target is compressed or archived, the data will be extracted to a temporary directory. It is the user's responsibility to delete this temporary directory, which is indicated by Project.path.

wn.project.iterpackages(path: str | Path, delete: bool = True) Iterator[Package]

Yield any wordnet or ILI packages found at path.

The path argument can point to one of the following:
  • a lexical resource file or ILI file

  • a wordnet package directory

  • a wordnet collection directory

  • a tar archive containing one of the above

  • a compressed (gzip or lzma) resource file or tar archive

The delete argument determines whether any created temporary directories will be deleted after iteration is complete. When it is True, the package objects can only be inspected during iteration. If one needs persistent objects (e.g., pkgs = list(iterpackages(...))), then set delete to False.

Warning

When delete is set to False, the user is responsible for cleaning up any temporary directories. The Project.path attribute indicates the path of the temporary directory.

wn.project.is_package_directory(path: str | Path) bool

Return True if path appears to be a wordnet or ILI package.

wn.project.is_collection_directory(path: str | Path) bool

Return True if path appears to be a wordnet collection.

Project Classes

Projects can be simple resource files, Package directories, or Collection directories. For API consistency, resource files are modeled as a virtual package (ResourceOnlyPackage).

class wn.project.Project

The base class for packages and collections.

This class is not used directly, but all subclasses will implement the methods listed here.

property path: Path

The path of the project directory or resource file.

For Package and Collection objects, the path is its directory. For ResourceOnlyPackage objects, the path is the same as from resource_file()

readme() Path | None

Return the path of the README file, or None if none exists.

license() Path | None

Return the path of the license, or None if none exists.

citation() Path | None

Return the path of the citation, or None if none exists.

class wn.project.Package(path: str | Path)

Bases: Project

A wordnet or ILI package.

A package is a directory with a resource file and optional metadata files.

property type: str | None

Return the name of the type of resource contained by the package.

Valid return values are: - "wordnet" – the resource is a WN-LMF lexicon file - "ili" – the resource is an interlingual index file - None – the resource type is undetermined

resource_file() Path

Return the path of the package's resource file.

class wn.project.ResourceOnlyPackage(path: str | Path)

Bases: Package

A virtual package for a single-file resource.

This class is for resource files that are not distributed in a package directory. The readme(), license(), and citation() methods all return None.

class wn.project.Collection(path: str | Path)

Bases: Project

A wordnet or ILI collection

Collections are directories that contain package directories and optional metadata files.

packages() list[Package]

Return the list of packages in the collection.