Jackson provides JsonPointer. However, I want to do something like that what https://github.com/json-path/JsonPath can provide. How do I describe this in JsonPointer?:
$.store.book[?(#.price < 10)]
somethink like:
JsonPointer p = JsonPointer.compile("/store/book[????]");
Related
Can you add a pattern file to a model?
matcher = Matcher(nlp_lg.vocab)
pattern = [{"LOWER": "tumulus"}]
matcher.add("thing", [pattern])
MyText = df.loc[52]["TEXT"]
doc = nlp_lg(MyText )
spacy.displacy.render(doc, style='ent')
It seems to make no difference and doesn't tag 'tumulus'.
Output:
"(Name: SS 26271656 ORG ) Woolley Barrows PERSON ( NR ORG ). (SS 26191653 CARDINAL ) Tumulus (NR)."
When you create a Matcher object, it has no special association with the pipeline, it's just an object that exists. Which is why it doesn't modify the pipeline output at all.
It sounds like what you want to do is add an EntityRuler - which is a component that wraps a Matcher - and have it overwrite entities. See the rule-based matching docs for an example of how to use the EntityRuler. It's a bit like this:
ruler = nlp.add_pipe("entity_ruler")
patterns = [{"label": "ORG", "pattern": [{"LOWER": "tumulus"}]}]
ruler.add_patterns(patterns)
Note nlp.add_pipe, which is key because it actually adds the component to the pipeline.
I have a few pull queries that look like this:
Site.objects(siteid).update_one(pull__somelist__refid=myid)
I would like to reuse this code by making 'somelist' a variable - something like this:
listvar = 'somelist'
Site.objects(siteid).update_one(pull__<listvar>__refid=myid)
I have tried various wrappers such as [listvar] and (listvar) without success.
Is there a way to inject the variable value into the query?
You should be able to abuse the kwarg notation for this
myvar = "some_var"
funky_kwarg = {f"pull__{myvar}__refid": myid}
Site.objects(siteid).update_one(**funky_kwarg)
I know that string interpolation can expose you to SQL injection, so you'd never want to do something like this:
user_input = params[:event_type]
Event.where("event.type = #{user_input}")
But what about using interpolation in a non-user-input context in the interest of code readability? Something like this:
class City
has_many :events
def important_events
big = "event.type = 1"
vip = "organizer.status > 10"
events.joins(:organizers)
.where("#{big} OR #{vip}")
end
end
Is this a bad idea? Is there a better way to do it?
(Using Rails 3)
I have 2 models (Vehicle and Capabilities) in a has_many through association.
So Vehicle 1 can have Capability 1 (eg towing), Capability 2 (eg passenger), Capability 3 (eg flying), etc.
v = Vehicle.first
v.capabilities.pluck(:name) #=> will give something like ['towing', 'passenger', 'flying']
I want to find all vehicles which must not have a particular capability, eg all vehicles which cannot fly.
I have tried queries similar to this below but it still includes flying vehicles, I think mainly because the airplane also has other capabilities.
non_flying = Vehicle.includes(:capabilities).where('capabilities.id NOT IN (?)', [2,3])
non_flying.first.capabilities.pluck(:name) #=> will give something like ['towing'].
Note that the flying capability is not included, but I just do not want this vehicle returned at all. How would I write this?
If possible, I would rather not use meta_wheel or squeel gems, but any arel_table implementation is welcome unless there is a simpler solution.
Try this query
non_flying = Vehicle.all - Vehicle.includes(:capabilities).where('capabilities.id IN (?)', [2,3]).all
I ended up doing something similar to this, inspired by Thaha kp's answer.
# Get all flying vehicles first
subquery = Vehicle.joins(:capabilities).where("capabilities.id IN (?)", 3).pluck("vehicles.id")
# Then get all vehicles not in this flying vehicles array
non_flying = Vehicle.where('vehicles.id NOT IN (?)', subquery).all
I have a mongo db complex filter generated dynamically which might look like
where_condition = {"$and":[{"column_3": "Offer"}, {"column_2":"MSN"}]}
collection.find(where_condition)
The condition might have unknown depth in $and and $or
Is it possible to find the negative of the where_condition
This does not work
not_condition = {"$not": where_condition}
You'll want to use $nor. Something like this:
where_condition = {"$and":[{"column_3": "Offer"}, {"column_2":"MSN"}]}
not_condition = {"$nor":[{"column_3": "Offer"}, {"column_2":"MSN"}]}
You can find some more info on the mongodb doc for $nor.