PyObjC Framework: LatentSemanticMapping
This library provides Python wrappers for Apple's LatentSemanticMapping framework on macOS, enabling Python applications to leverage latent semantic analysis capabilities for tasks like text similarity and natural language processing. It is part of the larger PyObjC project, currently at version 12.1, with releases typically tied to macOS SDK updates and Python version support cycles.
Warnings
- breaking PyObjC major versions frequently drop support for older Python versions. For example, v12.0 dropped Python 3.9 support, and v11.0 dropped Python 3.8. Ensure your Python environment meets the `requires_python` constraint for your PyObjC version.
- breaking PyObjC 11.1 aligned its Automatic Reference Counting (ARC) behavior for initializer methods with `clang`'s documentation. Methods in the 'init' family now correctly steal a reference to `self` and return a new reference. This is a fundamental change in reference counting semantics that could affect custom memory management or interaction with Objective-C objects.
- gotcha PyObjC 11.0 introduced experimental support for free-threading (PEP 703) in Python 3.13, requiring significant internal changes related to C Python API usage and borrowed references. While experimental, this could introduce subtle bugs or performance issues in multi-threaded applications using PyObjC with Python 3.13.
- gotcha PyObjC 10.3 temporarily broke the ability to use `__init__` in Python subclasses when a user-defined `__new__` method was present. This was partially reverted in 10.3.1: `__init__` can now be used if a user-implemented `__new__` exists, but not if relying on PyObjC's default `__new__`.
- gotcha Starting with PyObjC 12.1, Key-Value Observing (KVO) usage is automatically disabled for subclasses of `NSProxy` defined in Python. If your application relies on KVO notifications for changes in properties of such `NSProxy` subclasses, they will no longer be triggered.
Install
-
pip install pyobjc-framework-latentsemanticmapping
Imports
- LSMLanguageModel
from LatentSemanticMapping import LSMLanguageModel
- LSMSentence
from LatentSemanticMapping import LSMSentence
Quickstart
from LatentSemanticMapping import LSMSentence
import objc
# Instantiate a simple sentence object using the framework
sentence_string = "The quick brown fox jumps over the lazy dog."
sentence = LSMSentence.sentenceWithString_(sentence_string)
print(f"Created LSMSentence object: {sentence}")
print(f"Content: {sentence.string()}")
# You would typically use this with an LSMLanguageModel for semantic analysis
# (e.g., LSMLanguageModel.languageModelForLocale_options_error_)
# which requires specific setup (e.g., locale, options, or training data).