spaCy custom component with additional parameter - spacy

Is there a way to add an additional parameter (despite the doc) to a custom component?
More specifically I want to add some rule to a custom component as parameter.
match_word = "Anna"
def comp1(doc, match_word):
if match_word ==doc[0]:
# modify doc
return doc
nlp = add_pipe(comp1)
doc = nlp("Anna Smith lives in Melbourne")
Problem is that I pass a function to add_pipe without being able to pass any parameters.
Any hints why this does not make sense at all or how to solve it (differently) are very welcome.

Related

In blender, how to get the full parameter list of modifier and change specific parameter in python?

I have been searching for this online for a while but no proper answer solves my confusion.
There is a stair generator which contains several parameters in the modifier
Example snapshot
I want to change certain parameters such as
Dict["stair Count"] = 20
and somehow regenerate the model and output a ply/glb file.
In order to do so I want to get the list that modifier is showing, but I don't know how to do so in python.
import bpy
ctx = bpy.context
obj = ctx.object
nodes = obj.modifiers["STAIR GENERATOR"]
list(nodes.keys())
list(nodes.values())
I can see a list of the parameter values, but the keys seem quite wrong comparing to the GUI. So I have two questions.
How do I get a full list of the key label from python just like the GUI? (e.g. “Switch”, “stair count”, “stair height”, …)
How do I apply the change on the script and update the stairs?
Thank you in advance

Karate Runner with ExecutionHook listener

#Peter - As per your suggestion from my previous queries, I have used ExecutionHooks to implement ReportPortal. I am finding difficulties in passing all the required values from my Runner to Base Runner. Below is my configuration-
BaseRunner.java
Results results = Runner.parallel(tags,path,ScenarioName,Collections.singletonList(new
ScenarioReporter()),threads,karateOutputPath);
Runner.java
#KarateOptions(tags = { "#Shakedown" },
features = "classpath:tests/Shakedown"
)
I want to understand how can I pass the attributes like Scenario Name, path and tags. ScenarioReporter() is my class where I have implemented Execution Hook. I have a base runner that will have all the details and a normal runner that will have minimal information. I have just given snippets, please don't mind if there are some syntactical errors.
You don't need the annotations any more, and you can set all parameters including tags using the new "builder" (fluent interface) on the Runner. Refer the docs: https://github.com/intuit/karate#parallel-execution
Results results = Runner.path("classpath:some/package").tags("~#ignore").parallel(5);
So it should be easier to inherit from base classes etc. just figure out a way to pass a List<String> of tags and use it.
Just watch out for this bug, fixed in 0.9.6.RC1: https://github.com/intuit/karate/issues/1061

Calling a feature and passing in javascript variables

Been trying to figure this out for a while, please could someone help.
I have a set of 5 lines which I'd like to make reusable.
The lines do a "check event XXX has fired".
The lines make use of the "karate" variable and also the "json" command.
They're of the form:
* def message = myUtils.grabEvent(karate, myMessageListener)
* json event = message.text
* match event contains { ... some json in here ... }
* json eventPayload = event.payload
* match event contains { ... some payload json in here ... }
How do I go about making this reusable?
I have tried:
(A) Putting it all into a Javascript function
This failed because I don't know how to replicate the "json" command in Javascript
(B) Putting it all into a .feature file and calling that
This failed because I don't know how to pass the "karate" and "myMessageListener" variables into parameters of the .feature file.
Is it possible to put this into a reusable code block, please?
TIA
Yes I would recommend making this a reusable feature. Refer the documentation here: https://github.com/intuit/karate#calling-other-feature-files
And passing parameters is simple it would look like:
* def result = call read('reusable.feature')
Because by default, the "called" feature will "inherit" the variables of the calling feature.

Programmatically explore feature definitions

Is there any API to explore the definition of a feature (like the reflexion for code)?
My goal is for example to be able to do:
var myFeature = GetMyFeature("my feature guid")
var contentTypes = myFeature.Definition.ContentTypes
I know I can parse the xml files of the feature, but I'd like to avoid it.
Yes, you want to look at the SPFeature and SPFeatureDefinition types in the server object model.

Load template from a string instead of from a file

I have decided to save templates of all system emails in the DB.
The body of these emails are normal django templates (with tags).
This means I need the template engine to load the template from a string and not from a file. Is there a way to accomplish this?
Instantiate a django.template.Template(), passing the string to use as a template.
To complement the answer from Ignacio Vazquez-Abrams, here is the code snippet that I use to get a template object from a string:
from django.template import engines, TemplateSyntaxError
def template_from_string(template_string, using=None):
"""
Convert a string into a template object,
using a given template engine or using the default backends
from settings.TEMPLATES if no engine was specified.
"""
# This function is based on django.template.loader.get_template,
# but uses Engine.from_string instead of Engine.get_template.
chain = []
engine_list = engines.all() if using is None else [engines[using]]
for engine in engine_list:
try:
return engine.from_string(template_string)
except TemplateSyntaxError as e:
chain.append(e)
raise TemplateSyntaxError(template_string, chain=chain)
The engine.from_string method will instantiate a django.template.Template object with template_string as its first argument, using the first backend from settings.TEMPLATES that does not result in an error.
Using django Template together with Context worked for me on >= Django 3.
from django.template import Template, Context
template = Template('Hello {{name}}.')
context = Context(dict(name='World'))
rendered: str = template.render(context)