@CreoleResource(name="PythonPr",
helpURL="http://gatenlp.github.io/gateplugin-Python/",
comment="Use a Python program as a processing resource")
public class PythonPr
extends gate.creole.AbstractLanguageAnalyser
implements gate.creole.ControllerAwarePR, PythonCodeDriven
| Modifier and Type | Class and Description |
|---|---|
protected static class |
PythonPr.ExecuteResponse |
protected static class |
PythonPr.FinishResponse |
static class |
PythonPr.LoggingLevel
Possible python side logging level values.
|
| Modifier and Type | Field and Description |
|---|---|
protected URL |
configFile |
protected int |
duplicateId |
boolean |
isCompileOk
Last syntax check status.
|
protected Boolean |
isConfigured |
org.slf4j.Logger |
logger
Our logger instance.
|
protected PythonPr.LoggingLevel |
loggingLevel |
protected AtomicInteger |
nrDuplicates |
protected PythonPrResult |
outputResultResource |
protected gate.lib.interaction.process.pipes.Process4StringStream |
process
This field contains the currently active process for the python program.
|
protected gate.FeatureMap |
programParams |
protected String |
pythonBinary |
protected String |
pythonBinaryCommand |
protected URL |
pythonBinaryUrl |
protected gate.creole.ResourceReference |
pythonProgram |
protected File |
pythonProgramFile |
protected String |
pythonProgramFileInJar |
protected boolean |
pythonProgramIsJar |
protected boolean |
pythonProgramIsReadonly |
protected String |
pythonProgramModuleInJar |
protected String |
pythonProgramPathInJar |
protected URL |
pythonProgramUrl |
protected List<Object> |
resultList |
protected gate.gui.ResourceHelper |
rhBdocApi |
protected AtomicInteger |
runningDuplicates |
protected Set<String> |
setsToUse |
protected Boolean |
usePluginGatenlpPackage |
String |
usePythonPackagePath
The python package path to use when running Python.
|
ANNOTATION_COREF_FEATURE_NAME, DATE_ANNOTATION_TYPE, DATE_POSTED_ANNOTATION_TYPE, DEFAULT_FILE, DOCUMENT_COREF_FEATURE_NAME, JOB_ID_ANNOTATION_TYPE, LOCATION_ANNOTATION_TYPE, LOOKUP_ANNOTATION_TYPE, LOOKUP_CLASS_FEATURE_NAME, LOOKUP_INSTANCE_FEATURE_NAME, LOOKUP_LANGUAGE_FEATURE_NAME, LOOKUP_MAJOR_TYPE_FEATURE_NAME, LOOKUP_MINOR_TYPE_FEATURE_NAME, LOOKUP_ONTOLOGY_FEATURE_NAME, MONEY_ANNOTATION_TYPE, ORGANIZATION_ANNOTATION_TYPE, PERSON_ANNOTATION_TYPE, PERSON_GENDER_FEATURE_NAME, PLUGIN_DIR, SENTENCE_ANNOTATION_TYPE, SPACE_TOKEN_ANNOTATION_TYPE, TOKEN_ANNOTATION_TYPE, TOKEN_CATEGORY_FEATURE_NAME, TOKEN_KIND_FEATURE_NAME, TOKEN_LENGTH_FEATURE_NAME, TOKEN_ORTH_FEATURE_NAME, TOKEN_STRING_FEATURE_NAME| Constructor and Description |
|---|
PythonPr() |
| Modifier and Type | Method and Description |
|---|---|
void |
cleanup()
Cleanup resource.
|
void |
controllerExecutionAborted(gate.Controller controller,
Throwable throwable)
Callback when running over a wholr corpus terminates with an exception.
|
void |
controllerExecutionFinished(gate.Controller controller)
Callback when running over a whole corpus finishes.
|
void |
controllerExecutionStarted(gate.Controller controller)
Callback when running over a whole corpus starts.
|
static void |
copyResource(String source,
File targetPath)
Copy resource from plugin jar to target path.
|
void |
ensurePythonProgramCommand()
Make sure the python program command is set.
|
void |
execute()
Process document.
|
void |
figureOutPythonFile(URL pythonProgramUrl)
Figure out what kind of python file we use.
|
URL |
getConfigFile()
Get the config file URL.
|
int |
getDuplicateId()
Return the duplicate id of the PR instance.
|
Boolean |
getIsConfigured() |
PythonPr.LoggingLevel |
getLoggingLevel()
Get python logging level.
|
AtomicInteger |
getNrDuplicates()
Shared duplicates counter, getter.
|
PythonPrResult |
getOutputResultResource()
Result language resource, accessor.
|
gate.FeatureMap |
getProgramParams()
Get the program parameters.
|
String |
getPythonBinary()
Get the python interpreter command.
|
URL |
getPythonBinaryUrl()
Get the python interpreter file URL.
|
static String |
getPythonpathInZip()
Find the location of where the gatenlp package is in the jar or, for the
tests, in the classes directory.
|
gate.creole.ResourceReference |
getPythonProgram()
Get the python program path parameter.
|
File |
getPythonProgramFile()
Return the python file or null if in JAR.
|
String |
getPythonProgramString()
Return the python program as String.
|
URL |
getPythonProgramUrl()
Return URL of the python program we determined.
|
protected String |
getResponseError(Map<String,Object> response) |
List<Object> |
getResultList()
Result list getter.
|
AtomicInteger |
getRunningDuplicates()
Return the value of the currently running duplicates counter.
|
Set<String> |
getSetsToUse()
Get which annotation set names to use.
|
Boolean |
getUsePluginGatenlpPackage()
Get the ownGatenlpPackage parameter value.
|
gate.Resource |
init()
Initialise resource.
|
static boolean |
isOsWindows()
Check if we are running on windows.
|
static String[] |
jarUrl2PythonPathAndModule(URL jarUrl)
Return the path and module from a JAR URL.
|
protected String |
makeExecuteRequest(gate.Document doc)
Create and return the JSON String representing an execute request.
|
protected String |
makeFinishRequest() |
protected String |
makeReduceRequest() |
protected String |
makeStartRequest() |
boolean |
pythonFileCanBeEdited()
Return flag indicating if the python file can be edited.
|
void |
registerEditorVR(PythonEditorVr vr)
Register the visual resource.
|
void |
reInit()
Re-initialize resource.
|
static String |
removeValidProtocols(String urlString)
Given a jar/file URL, remove the valid protocol parts.
|
void |
setConfigFile(URL value)
URL of a config file.
|
void |
setIsConfigured(Boolean value) |
void |
setLoggingLevel(PythonPr.LoggingLevel value)
Select log level on the python side.
|
void |
setNrDuplicates(AtomicInteger value)
Shared duplicates counter, setter.
|
void |
setOutputResultResource(PythonPrResult value)
Result language resource to store any corpus processing results.
|
void |
setProgramParams(gate.FeatureMap parms)
Set parameters to send to the python program.
|
void |
setPythonBinary(String value)
Set the python interpreter command name.
|
void |
setPythonBinaryUrl(URL value)
The file URL for a python interpreter to use.
|
void |
setPythonProgram(gate.creole.ResourceReference value)
Set the location of the python program.
|
void |
setResultList(List<Object> value)
Result list setter.
|
void |
setRunningDuplicates(AtomicInteger value)
Number of duplicates running on a corpus.
|
void |
setSetsToUse(Set<String> val)
Set the annotation set names to use.
|
void |
setUsePluginGatenlpPackage(Boolean value)
If we should use our own (the plugin's) copy of the Python gatenlp package.
|
boolean |
tryCompileProgram()
Rough check if the program can be compiled.
|
protected void |
whenFinishing() |
protected void |
whenStarting()
This will run whenever a corpus gets run.
|
getCorpus, getDocument, setCorpus, setDocumentaddProgressListener, addStatusListener, fireProcessFinished, fireProgressChanged, fireStatusChanged, getRuntimeParameterValues, getRuntimeParameterValues, interrupt, isInterrupted, removeProgressListener, removeStatusListenercheckParameterValues, flushBeanInfoCache, forgetBeanInfo, getBeanInfo, getInitParameterValues, getInitParameterValues, getName, getParameterValue, getParameterValue, getParameterValues, removeResourceListeners, setName, setParameterValue, setParameterValue, setParameterValues, setParameterValues, setResourceListeners, toStringclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitprotected gate.creole.ResourceReference pythonProgram
protected URL configFile
protected boolean pythonProgramIsJar
protected boolean pythonProgramIsReadonly
protected File pythonProgramFile
protected String pythonProgramPathInJar
protected String pythonProgramModuleInJar
protected String pythonProgramFileInJar
protected URL pythonProgramUrl
protected gate.FeatureMap programParams
protected String pythonBinary
protected URL pythonBinaryUrl
protected String pythonBinaryCommand
protected Boolean isConfigured
protected PythonPr.LoggingLevel loggingLevel
protected Boolean usePluginGatenlpPackage
protected PythonPrResult outputResultResource
protected transient gate.lib.interaction.process.pipes.Process4StringStream process
public transient org.slf4j.Logger logger
protected AtomicInteger nrDuplicates
protected AtomicInteger runningDuplicates
protected int duplicateId
public boolean isCompileOk
public String usePythonPackagePath
protected gate.gui.ResourceHelper rhBdocApi
@Optional
@CreoleParameter(comment="The (file or jar) URL of the Python program to run",
suffixes=".py")
public void setPythonProgram(gate.creole.ResourceReference value)
value - the URL pointing to the python file.public gate.creole.ResourceReference getPythonProgram()
@Optional @RunTime @CreoleParameter(comment="The (file or jar) URL of the Python program to run") public void setConfigFile(URL value)
value - the config file URLpublic URL getConfigFile()
@Optional @RunTime @CreoleParameter(comment="Extra parameters to pass on to the Python program") public void setProgramParams(gate.FeatureMap parms)
parms - a FeatureMap of parameterspublic gate.FeatureMap getProgramParams()
@Optional
@RunTime
@CreoleParameter(comment="Python interpreter name (on system PATH)",
disjunction="pythonbin",
priority=1,
defaultValue="python")
public void setPythonBinary(String value)
value - the python interpreter commandpublic String getPythonBinary()
@Optional
@RunTime
@CreoleParameter(comment="Python interpreter file URL. If provided overrides pythonBinary.",
priority=10,
disjunction="pythonbin")
public void setPythonBinaryUrl(URL value)
value - python interpreter program filepublic URL getPythonBinaryUrl()
@CreoleParameter(defaultValue="false") @HiddenCreoleParameter public void setIsConfigured(Boolean value)
public Boolean getIsConfigured()
@Optional
@RunTime
@CreoleParameter(comment="Logging level to use on the python side",
defaultValue="INFO")
public void setLoggingLevel(PythonPr.LoggingLevel value)
value - one of the LoggingLevel enum valuespublic PythonPr.LoggingLevel getLoggingLevel()
@Optional
@RunTime
@CreoleParameter(comment="Use Python gatenlp package included in the plugin, not the system one.",
defaultValue="true")
public void setUsePluginGatenlpPackage(Boolean value)
value - Flag inidicating if own gatenlp package should be usedpublic Boolean getUsePluginGatenlpPackage()
@Optional @RunTime @CreoleParameter(comment="Result object.") public void setOutputResultResource(PythonPrResult value)
value - a PythonPrResult language resourcepublic PythonPrResult getOutputResultResource()
@Optional
@RunTime
@CreoleParameter(comment="Annotation set names to send and use in Python, *=all, null/space=default set",
defaultValue="*")
public void setSetsToUse(Set<String> val)
val - the set of set names to use.public Set<String> getSetsToUse()
@Sharable public void setNrDuplicates(AtomicInteger value)
value - the counterpublic AtomicInteger getNrDuplicates()
@Sharable public void setResultList(List<Object> value)
value - should be a synchronized list@Sharable public void setRunningDuplicates(AtomicInteger value)
value - the valuepublic AtomicInteger getRunningDuplicates()
public int getDuplicateId()
public void ensurePythonProgramCommand()
public void figureOutPythonFile(URL pythonProgramUrl)
pythonProgramUrl - python progrsam urlpublic boolean pythonFileCanBeEdited()
public URL getPythonProgramUrl()
public String getPythonProgramString()
public File getPythonProgramFile()
public boolean tryCompileProgram()
The python program is run as a normal program if it is a normal file, if it is in the jar, it gets invoked by loading it as a library.
public void registerEditorVR(PythonEditorVr vr)
vr - visual resourcepublic static String[] jarUrl2PythonPathAndModule(URL jarUrl)
jarUrl - expected to point to a python file inside a jarpublic static String removeValidProtocols(String urlString)
urlString - the URL stringpublic static String getPythonpathInZip()
public gate.Resource init()
throws gate.creole.ResourceInstantiationException
init in interface gate.Resourceinit in class gate.creole.AbstractProcessingResourcegate.creole.ResourceInstantiationException - could not initialiseprotected void whenStarting()
protected void whenFinishing()
public void reInit()
throws gate.creole.ResourceInstantiationException
reInit in interface gate.ProcessingResourcereInit in class gate.creole.AbstractProcessingResourcegate.creole.ResourceInstantiationException - exception if initialisation failspublic void cleanup()
cleanup in interface gate.Resourcecleanup in class gate.creole.AbstractProcessingResourcepublic void execute()
throws gate.creole.ExecutionException
execute in interface gate.Executableexecute in class gate.creole.AbstractProcessingResourcegate.creole.ExecutionException - exception when processing failspublic void controllerExecutionStarted(gate.Controller controller)
controllerExecutionStarted in interface gate.creole.ControllerAwarePRcontroller - the controller usedpublic void controllerExecutionFinished(gate.Controller controller)
controllerExecutionFinished in interface gate.creole.ControllerAwarePRcontroller - the controller usedpublic void controllerExecutionAborted(gate.Controller controller,
Throwable throwable)
controllerExecutionAborted in interface gate.creole.ControllerAwarePRcontroller - the controller usedthrowable - the throwable from the exceptionprotected String makeExecuteRequest(gate.Document doc)
doc - the document to send overprotected String makeStartRequest()
protected String makeFinishRequest()
protected String makeReduceRequest()
public static void copyResource(String source, File targetPath)
source - the path of the resource to copytargetPath - where to copy to, must not already existpublic static boolean isOsWindows()
Copyright © 2021 GATE Team. All rights reserved.