- spaCy Tutorial
- spaCy - Home
- spaCy - Introduction
- spaCy - Getting Started
- spaCy - Models and Languages
- spaCy - Architecture
- spaCy - Command Line Helpers
- spaCy - Top-level Functions
- spaCy - Visualization Function
- spaCy - Utility Functions
- spaCy - Compatibility Functions
- spaCy - Containers
- Doc Class ContextManager and Property
- spaCy - Container Token Class
- spaCy - Token Properties
- spaCy - Container Span Class
- spaCy - Span Class Properties
- spaCy - Container Lexeme Class
- Training Neural Network Model
- Updating Neural Network Model
- spaCy Useful Resources
- spaCy - Quick Guide
- spaCy - Useful Resources
- spaCy - Discussion
spaCy - Compatibility Functions
As we know that all Python codes are written in an intersection of Python2 and Python3 which may be not that fine in Python. But, that is quite easy in Cython.
The compatibility functions in spaCy along with its description are listed below −
Compatibility Function | Description |
---|---|
Spacy.compat() | Deals with Python or platform compatibility. |
compat.is_config() | Checks whether a specific configuration of Python version and operating system (OS) matches the user’s setup. |
Spacy.compat()
It is the function that has all the logic dealing with Python or platform compatibility. It is distinguished from other built-in function by suffixed with an underscore. For example, unicode_.
Some examples are given in the table below −
NAME | PYTHON 2 | PYTHON 3 |
---|---|---|
compat.bytes_ | str | bytes |
compat.unicode_ | unicode | str |
compat.basestring_ | basestring | str |
compat.input_ | raw_input | input |
compat.path2str | str(path) with .decode('utf8') | str(path) |
Example
An example of spacy.compat() function is as follows −
import spacy from spacy.compat import unicode_ compat_unicode = unicode_("This is Tutorialspoint") compat_unicode
Output
Upon execution, you will receive the following output −
'This is Tutorialspoint'
compat.is_config()
It is the function that checks whether a specific configuration of Python version and operating system (OS) matches the user’s setup. This function is mostly used for displaying the targeted error messages.
Arguments
The table below explains its arguments −
NAME | TYPE | DESCRIPTION |
---|---|---|
python2 | Bool | Whether spaCy is executed with Python 2.x or not. |
python3 | Bool | Whether spaCy is executed with Python 3.x or not. |
windows | Bool | Whether spaCy is executed on Windows or not. |
linux | Bool | Whether spaCy is executed on Linux or not. |
OS X | Bool | Whether spaCy is executed on OS X or not. |
Example
An example of compat.is_config() function is as follows −
import spacy from spacy.compat import is_config if is_config(python3=True, windows=True): print("Spacy is executing on Python 3 on Windows.")
Output
Upon execution, you will receive the following output −
Spacy is executing on Python 3 on Windows.