Package: pyjsonnlp
Python JSON-NLP Module(C) 2019 byDamir Cavar,Oren Baldinger,Maanvitha Gongalla,Anurag Kumar, Murali KammiliBrought to you by theNLP-Lab.org!IntroductionThere is a growing number of Natural Language Processing (NLP) tools, modules, pipelines. There does not seem to be any standard for the output format. Here we are focusing on a standard for the output format syntax. Some future version ofJSON-NLPmight address the output semantics as well.JSON-NLPis a standard for the most important outputs NLP pipelines and components can generate. The relevant documentation can be found in theJSON-NLPGitHub repo and on its website at the [NLP-Lab].The PythonJSON-NLPmodule contains general mapping functions forJSON-NLPtoCoNLL-U, a validator for the generated output, an NLP pipeline interface (forFlair,spaCy,NLTK,Polyglot,Xrenner, etc.), and various utility functions.There is aJava JSON-NLPMaven module as well, and there are wrappers for numerous popular NLP pipelines and tools linked from theNLP-Lab.orgwebsite.InstallationFor more details, seeJSON-NLP.This module is a wrapper for outputs from different NLP pipelines and modules into a standardizedJSON-NLPformat.To install this package, run the following command:pip install pyjsonnlpYou might have to usepip3on some systems.ValidationJSON-NLPis based on a schema, built byNLP-Lab.org, to comprehensively and concisely represent linguistic annotations.
We provide a validator to help ensure that generated JSON validates against the schema:result = MyPipeline().proces(text="I am a sentence")
assert pyjsonnlp.validation.is_valid(result)ConversionTo enable interoperability with other annotation formats, we support conversions between them.
Note that conversion could be lossy, if the relative depths of annotation are not the same.
Currently we have aCoNLL-UtoJSON-NLPconverter, that covers most annotations:pyjsonnlp.conversion.parse_conllu(conllu_text)To convert the other direction:pyjsonnlp.conversion.to_conllu(jsonnlp)PipelineJSON-NLPprovides a simplePipelineinterface that should be implemented for embedding into a microservice:from collections import OrderedDict

class MockPipeline(pyjsonnlp.pipeline.Pipeline):
    @staticmethod
    def process(text='', coreferences=False, constituents=False, dependencies=False, expressions=False,
                **kwargs) -> OrderedDict: 
        return OrderedDict()The provided keyword arguments should be used to toggle on or off processing components within the method.If you have deployed aPipelineas a microservice (see below), we provide a local endpoint for a remotely
deployedPipelinevia theRemotePipelineclass:pipeline = pyjsonnlp.pipeline.RemotePipeline('localhost', port=9000)
print(pipeline.process(text='I am a sentence', dependencies=True, something='else'), spacing=2)MicroserviceThe next step is theJSON-NLPa Microservice class, with a pre-built implementation of [Flask].from pyjsonnlp.microservices.flask_server import FlaskMicroservice

app = FlaskMicroservice(__name__, MyPipeline(), base_route='/')We recommend creating aserver.pywith theFlaskMicroserviceclass, which extends the [Flask] app. A corresponding WSGI file would contain:from mypipeline.server import app as applicationTo disable a pipeline component (such as phrase structure parsing), addapplication.constituents = FalseThe full list of properties available that can be disabled or enabled areconstituentsdependenciescoreferenceexpressionsThe microservice exposes the following URIs:/constituents/dependencies/coreference/expressions/token_listThese URIs are shortcuts to disable the other components of the parse. In all cases,tokenListwill be included in theJSON-NLPoutput. An example url is:http://localhost:5000/dependencies?text=I am a sentenceText is provided to the microservice with thetextparameter, via eitherGETorPOST. If you passurlas a parameter, the microservice will scrape that url and process the text of the website.Other parameters specific to your pipeline implementation can be passed as well:http://localhost:5000?lang=en&constituents=0&text=I am a sentence.