public class PythonParser extends Object implements InformationExtractionParser
Modifier and Type | Class and Description |
---|---|
static class |
PythonParser.ParseExecutor
An Executor that performs parse request and completion tasks.
|
static class |
PythonParser.PythonDispatcherCallback
PythonDispatcherCallback is used to manage the Executor used to
communicate with the Python process.
|
REGEXRULE_MARKER
Constructor and Description |
---|
PythonParser()
Default constructor for an PythonParser.
|
Modifier and Type | Method and Description |
---|---|
void |
copyOutputFile(String tempDir,
String outputFileName)
Copy the output file.
|
void |
copyTempFile(String tempFilePath)
Copy a temp file prior to executing a parse.
|
protected Document |
createJsonResultDocument(String jsonFile)
Create the JSON result document that contains the raw NLP information
generated in spaCy.
|
protected AccessControlList |
determineJsonResultDocumentAcl(InformationExtraction ext)
Determine the ACL to use for the Json Result document.
|
protected String |
determineJsonResultDocumentName(InformationExtraction ext)
Determine the Name to use for the Json Result document.
|
protected Folder |
determineJsonResultDocumentParentFolder(InformationExtraction ext)
Determine the parent Folder to use for the Json Result document.
|
protected Document |
getDocument(AttributeValue av,
LibrarySession session)
Gets a Document object from the specified AttributeValue,
which can reference a Document, Family, or VersionSeries.
|
InformationExtraction |
getInformationExtraction()
Gets the InformationExtraction being processed.
|
List<String> |
getPythonCommandList(String pythonFile)
Gets the list of arguments to launch the Python process.
|
protected String |
getPythonScriptContent()
Gets (or derives) the python script to execute.
|
protected String |
getPythonScriptUniqueIdentifer()
Gets the identifer to use for the generated python script.
|
AttributeValueTable |
getSettings()
Gets the effective settings for the current parse.
|
static long |
getTempFileCounter()
Gets a unique (to this JVM) temp file counter.
|
void |
initialize(InformationExtractionParserSpecification spec)
Initialize this instance.
|
String |
normalizeTempFilePath(String tempDir,
String filePath)
Normalize (modify) the temp file path specified.
|
void |
parse(InformationExtraction ext)
Performs a parse of the target InformationExtraction,
without a handler context.
|
void |
parse(InformationExtraction ext,
InformationExtractionHandlerDispatcher handler)
Performs a parse of the target InformationExtraction,
with a handler context.
|
protected void |
preParse()
Perform task prior to executing the parse.
|
protected void |
processJsonOutputs(JsonObject outputsObj)
Processes the outputs produced in Python, from the specified
JsonObject.
|
void |
setInformationExtraction(InformationExtraction ext)
Sets the InformationExtraction being processed.
|
protected void |
setJsonInputs(JsonObject inputsObj)
Sets the inputs to be sent to Python, in the specified
JsonObject.
|
public PythonParser()
public void initialize(InformationExtractionParserSpecification spec) throws IfsException
Called immediately after construction (via the default constructor) and used so that the implementation can initialize session-independent state.
initialize
in interface InformationExtractionParser
spec
- The specification for a given implementation.IfsException
- if the operation fails.public AttributeValueTable getSettings()
public static long getTempFileCounter()
public void setInformationExtraction(InformationExtraction ext)
ext
- the InformationExtraction being processedpublic InformationExtraction getInformationExtraction()
protected Document getDocument(AttributeValue av, LibrarySession session) throws IfsException
IfsException
- if the operation failspublic void parse(InformationExtraction ext) throws IfsException
parse
in interface InformationExtractionParser
ext
- the target InformationExtractionIfsException
- if the operation failspublic void parse(InformationExtraction ext, InformationExtractionHandlerDispatcher handler) throws IfsException
parse
in interface InformationExtractionParser
ext
- the target InformationExtractionhandler
- the handler requesting the parse (can be null)IfsException
- if the operation failsprotected void setJsonInputs(JsonObject inputsObj) throws IfsException
inputsObj
- the JSON inputsIfsException
- if the operation failsprotected String getPythonScriptContent() throws IfsException
IfsException
- if the operation failsprotected String getPythonScriptUniqueIdentifer() throws IfsException
Can be null if the Python script provided by
getPythonScriptContent
does not vary.
IfsException
- if the operation failsprotected Document createJsonResultDocument(String jsonFile) throws IfsException
jsonFile
- the results file nameIfsException
- if the operation failsprotected String determineJsonResultDocumentName(InformationExtraction ext) throws IfsException
ext
- the InformationExtraction being preparedIfsException
- if the operation failsprotected AccessControlList determineJsonResultDocumentAcl(InformationExtraction ext) throws IfsException
ext
- the InformationExtraction being preparedIfsException
- if the operation failsprotected Folder determineJsonResultDocumentParentFolder(InformationExtraction ext) throws IfsException
ext
- the InformationExtraction being preparedIfsException
- if the operation failsprotected void processJsonOutputs(JsonObject outputsObj) throws IfsException
outputsObj
- the JSON outputsIfsException
- if the operation failsprotected void preParse() throws IfsException
Override to pick up settings.
IfsException
- if the operation failspublic String normalizeTempFilePath(String tempDir, String filePath) throws IfsException
tempDir
- the absolute path to the temp file directory,
which is typically the prefix of the filePathfilePath
- the absolute path to the temp fileIfsException
- if the operation failspublic void copyTempFile(String tempFilePath) throws IfsException
tempFilePath
- the absolute path to the temp fileIfsException
- if the operation failspublic void copyOutputFile(String tempDir, String outputFileName) throws IfsException
tempDir
- the absolute path to the temp file directoryoutputFileName
- the name of the output fileIfsException
- if the operation failsCopyright © 2023. All rights reserved.