wn.project¶
Wordnet and ILI Packages and Collections
- wn.project.get_project(*, project: str | None = None, path: str | Path | None = None) Project¶
Return the
Projectobject 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 theCollectionobject 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 toFalse.Warning
When delete is set to
False, the user is responsible for cleaning up any temporary directories. TheProject.pathattribute indicates the path of the temporary directory.
- wn.project.is_package_directory(path: str | Path) bool¶
Return
Trueif path appears to be a wordnet or ILI package.
- wn.project.is_collection_directory(path: str | Path) bool¶
Return
Trueif 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
PackageandCollectionobjects, the path is its directory. ForResourceOnlyPackageobjects, the path is the same as fromresource_file()
- class wn.project.Package(path: str | Path)¶
Bases:
ProjectA wordnet or ILI package.
A package is a directory with a resource file and optional metadata files.