Package: qai
library.qai.utilitiesHelper functions and classes for interacting with the rest of the Writer platform. The main components are:qai.issues.make_issue: makes a dictionary that conforms to Writer platform standardsqai.spacy_factor.SpacyFactor: a helper class which turns a spaCy Span into an issueqai.server.QRest: a helper class which builds a Sanic REST server for youqai.validation.Validator: a simple validator class that can be used to skip segments without processing them, e.g. for being empty or having HTML. You would only want to import this yourself if you aren't usingQRestIf you are building a Sanic app without usingQRest, you still may be interested in the following middleware:qai.server.set_valid_segments: stores valid segments torequest.ctx.segmentsand also setsrequest.ctx.infoqai.server.postprocess_issues: changes the string indexing to be utf-16 based, and filters no ops(See GitHub history for older docs - QAI used to do a lot more!)Upgrading to v5Analyzerclass must now be callable. It will be passed(segment: str, meta: dict, all_info: dict)-segmentis the string to analyze,metais themetaobject that was sent, or{}if none was sent, andall_infois the entire payload the server received - in case you need access to clientID or something. Feel free to definedef __call__(self, segment: str, meta: dict, _)if you don't expect to need the request.QRestcan be passed a Sanic app, or be passed a dictionary which maps issue types to categories (in addition to the default behavior). This is useful for services that handle multiple categories, for which the default behavior doesn't work.QAI has a simpler structure, so all imports look differentConfigs, Strings, Storage, and Document are gone. The later 2 because they aren't needed anymore, the former 2 because you should manage that yourself. Whitelisting is also gone - just don't make the issues if you don't want them.All issues are created in the v2 format (meaning, the format we switched to after new segmentation - definedhere)By default, issuefromanduntilkeys are now based on UTF-16 indexing, to make things easier for JS. We add_from_pand_until_pkeys for debugging, which are the Python string indexes. This happens as response middleware in QRest.UsageYou can explicitly create a REST connection like this:fromappimportAnalyzerfromqai.serverimportQRest# setting the category / service name does nothing# we use the category passed on the requestcategory='service_name'host='0.0.0.0'port=5000if__name__=='__main__':analyzer=Analyzer()rest_connection=QRest(analyzer,category=category,host=host,port=port)# create a blocking connection:rest_connection.connect()The above will createas many workers as you have cores.This is great, sometimes. For example, there is a known bug where AutoML crashes if you are using more than one worker. So passworkers=1if this happensThere is also a helper class for turning spaCySpans into issues the rest of the platform can process:fromspacy.tokensimportSpanfromqai.spacy_factorimportSpacyFactorMyFactor=SpacyFactor("subject_object_verb_spacing","Keep the subject, verb, and object of a sentence close together to help the reader understand the sentence.")Span.set_extension("score",default=0)Span.set_extension("suggestions",default=[])doc=nlp("Holders of the Class A and Class B-1 certificates will be entitled to receive on each Payment Date, to the extent monies are available therefor (but not more than the Class A Certificate Balance or Class B-1 Certificate Balance then outstanding), a distribution.")score=analyze(doc)ifscoreisnotNone:span=Span(doc,0,len(doc))# or whichever tokens/spans are the issue (don't have to worry about character indexes)span._.score=scorespan._.suggestions=get_suggestions(doc)issue=MyFactor(span)Installationpip install qaiorpoetry add qaiTestingSee Confluence for docs on input format expectations.scripts/test_qai.shhas some helpful testing functions.CI/CDGitHub Actions will push to PyPi when you merge into themainbranch.LicenseThis software is not licensed. If you do not work at Writer, you are not legally allowed to use it. Also, it's just helper functions that really won't help you. If something in it does look interesting, and you would like access or our help, open an issue.