Comments (2)
Here's an implementation of the parser for python-like string matches:
import json
# https://docs.mongodb.com/manual/reference/operator/query-comparison
_OPERATORS = {
">": "$gt",
">=": "$gte",
"==": "$eq",
"!=": "$ne",
"<": "$lt",
"<=": "$lte",
"in": "$in",
"not in": "$nin",
}
def parse_query(s):
chunks = s.split()
if len(chunks) < 3:
raise ValueError(
"Invalid query string '%s'; all queries must have the syntax "
"'<field> <operator> <value>'" % s
)
if (len(chunks) > 3) and (chunks[1:3] == ["not", "in"]):
chunks = [chunks[0], "not in"] + chunks[3:]
if len(chunks) > 3:
chunks = chunks[:2] + [" ".join(chunks[2:])]
field, op, val = chunks
if op not in _OPERATORS:
raise ValueError(
"Unsupported comparison operation '%s'; the supported operations "
"are {%s}" % (op, ", ".join(_OPERATORS.keys()))
)
try:
return {field: {_OPERATORS[op]: json.loads(val)}}
except json.JSONDecodeError:
raise ValueError("Query value '%s' must be JSON parsable" % val)
Example uses:
print(parse_query("metadata.size_bytes > 1200"))
# {'metadata.size_bytes': {'$gt': 1200}}
print(parse_query('tag not in ["test", "train"]'))
# {'tag': {'$nin': ['test', 'train']}}
print(parse_query("metadata.size_bytes ~= 1200"))
# ValueError: Unsupported comparison operation '~='; the supported operations are {>, >=, ==, !=, <, <=, in, not in}
print(parse_query('tag not in {"test", "train"}'))
# ValueError: Query value '{"test", "train"}' must be JSON parsable
from fiftyone.
Resolved by #290
from fiftyone.
Related Issues (20)
- Why do open web pages display 'Not Found'? HOT 2
- [BUG] : AttributeSchemaError: Expected attribute 'value' to have type 'eta.core.data.NumericAttribute'; found 'eta.core.data.CategoricalAttribute' HOT 3
- [BUG] Clearing the tags field and then tagging samples raises error
- [FR] Do not display the bounding box for instance segmentations
- [DOCS] Transparency of user tracking HOT 2
- [BUG] ctx.selected_labels is empty in resolve_input and resolve_output HOT 2
- [BUG] `contains` with `all=True` does not safely resolve
- [BUG] Change color of certain bounding boxes on FiftyOne browser app HOT 1
- [BUG] GraphQL API Error HOT 2
- DocumentTooLarge: 'aggregate' command document too large HOT 2
- [BUG] Checkbox value not updated when uploading to CVAT
- [FR] implement cloudpathlibs AnyPath to all file IO HOT 1
- [BUG] Custom operator doesn't work for types.Button()
- [BUG] Plotting interactive confusion matrix doesn't work when using an eval_key in the evaluation HOT 2
- [BUG] Failed to load non-standard VOC XML annotation format.
- [BUG] Got 403 error when running FiftyOne on Google Colaboratory HOT 2
- Is there a way to skip non annotated images during conversion from coco to kitti? HOT 2
- [BUG] IOU threshold does not change results.plot_pr_curve() HOT 2
- [BUG]When annotating ImageSegmentation type with cvat, if a mask is completely surrounded by another, the surrounded mask won't be loaded correctly
- [FR] Contextual images for CVAT annotation HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fiftyone.