···11from pasturepy.constants.fields import EMBED_TYPES
22from pasturepy.constants.graze_json import EMBED_COMPARISONS
3344+45class EmbedNode:
55-66 @staticmethod
77 def embed(filter_group, comparison: str, embed_type: str):
88 """Filter by embeds (images, videos, gifs, links)"""
99 if embed_type not in EMBED_TYPES:
1010- raise ValueError(f"Invalid method '{embed_type}'. Must be one of {EMBED_TYPES}")
1010+ raise ValueError(
1111+ f"Invalid method '{embed_type}'. Must be one of {EMBED_TYPES}"
1212+ )
1113 if comparison not in EMBED_COMPARISONS:
1212- raise ValueError(f"Invalid entity_type '{comparison}'. Must be one of {EMBED_COMPARISONS}")
1313-1414- return filter_group.add_filter({
1515- "embed_type": [comparison, embed_type]
1616- })1414+ raise ValueError(
1515+ f"Invalid entity_type '{comparison}'. Must be one of {EMBED_COMPARISONS}"
1616+ )
1717+1818+ return filter_group.add_filter({"embed_type": [comparison, embed_type]})
+9-7
pasturepy/nodes/entity.py
···11from pasturepy.constants.fields import ENTITY_TYPES
22from pasturepy.constants.graze_json import ENTITY_METHODS
3344+45class EntityNode:
55-66 @staticmethod
77 def entity(filter_group, method: str, entity_type: str, terms: list):
88 """Filter by entities (hashtags, mentions, domains, etc.)."""
99 if method not in ENTITY_METHODS:
1010- raise ValueError(f"Invalid method '{method}'. Must be one of {ENTITY_METHODS}")
1010+ raise ValueError(
1111+ f"Invalid method '{method}'. Must be one of {ENTITY_METHODS}"
1212+ )
1113 if entity_type not in ENTITY_TYPES:
1212- raise ValueError(f"Invalid entity_type '{entity_type}'. Must be one of {ENTITY_TYPES}")
1313-1414- return filter_group.add_filter({
1515- method: [entity_type, terms]
1616- })1414+ raise ValueError(
1515+ f"Invalid entity_type '{entity_type}'. Must be one of {ENTITY_TYPES}"
1616+ )
1717+1818+ return filter_group.add_filter({method: [entity_type, terms]})
+62-55
pasturepy/nodes/ml.py
···11from pasturepy.constants.graze_json import COMPARISONS
22from pasturepy.constants.values import (
33- CONTENT_MODS, IMAGE_MODS, TOPICS, LANGUAGES,
44- SENTIMENTS, TOXICITY, EMOTIONS, CATEGORIES, SPAM_TYPE
33+ CATEGORIES,
44+ CONTENT_MODS,
55+ EMOTIONS,
66+ IMAGE_MODS,
77+ LANGUAGES,
88+ SENTIMENTS,
99+ SPAM_TYPE,
1010+ TOPICS,
1111+ TOXICITY,
512)
1313+614715class MLNode:
88-916 @staticmethod
1017 def _validate_comparison(comparison: str) -> None:
1118 if comparison not in COMPARISONS:
1212- raise ValueError(f"Invalid comparison '{comparison}'. Must be one of {COMPARISONS}")
1313-1919+ raise ValueError(
2020+ f"Invalid comparison '{comparison}'. Must be one of {COMPARISONS}"
2121+ )
2222+1423 @staticmethod
1524 def _validate_probability(value: float) -> None:
1625 if not (0 <= value <= 1):
1726 raise ValueError(f"Probability must be between 0 and 1, got {value}")
1827 if round(value, 2) != value:
1928 raise ValueError("Probability can only have up to 2 decimal places")
2020-2929+2130 @staticmethod
2222- def content_moderation(filter_group, content_type: str, comparison: str, value: float):
3131+ def content_moderation(
3232+ filter_group, content_type: str, comparison: str, value: float
3333+ ):
2334 if content_type not in CONTENT_MODS:
2435 raise ValueError(f"Invalid content_type. Must be one of {CONTENT_MODS}")
2536 MLNode._validate_comparison(comparison)
2637 MLNode._validate_probability(value)
2727-2828- return filter_group.add_filter({
2929- "content_moderation": [content_type, comparison, value]
3030- })
3131-3838+3939+ return filter_group.add_filter(
4040+ {"content_moderation": [content_type, comparison, value]}
4141+ )
4242+3243 @staticmethod
3344 def image_nsfw(filter_group, mod_type: str, comparison: str, value: float):
3445 if mod_type not in IMAGE_MODS:
3546 raise ValueError(f"Invalid mod_type. Must be one of {IMAGE_MODS}")
3647 MLNode._validate_comparison(comparison)
3748 MLNode._validate_probability(value)
3838-3939- return filter_group.add_filter({
4040- "image_nsfw": [mod_type, comparison, value]
4141- })
4242-4949+5050+ return filter_group.add_filter({"image_nsfw": [mod_type, comparison, value]})
5151+4352 @staticmethod
4453 def language(filter_group, language: str, comparison: str, value: float):
4554 if language not in LANGUAGES:
4655 raise ValueError(f"Invalid language. Must be one of {LANGUAGES}")
4756 MLNode._validate_comparison(comparison)
4857 MLNode._validate_probability(value)
4949-5050- return filter_group.add_filter({
5151- "language_analysis": [language, comparison, value]
5252- })
5858+5959+ return filter_group.add_filter(
6060+ {"language_analysis": [language, comparison, value]}
6161+ )
53625463 @staticmethod
5564 def sentiment(filter_group, sentiment: str, comparison: str, value: float):
···5766 raise ValueError(f"Invalid sentiment. Must be one of {SENTIMENTS}")
5867 MLNode._validate_comparison(comparison)
5968 MLNode._validate_probability(value)
6060-6161- return filter_group.add_filter({
6262- "sentiment_analysis": [sentiment, comparison, value]
6363- })
6464-6969+7070+ return filter_group.add_filter(
7171+ {"sentiment_analysis": [sentiment, comparison, value]}
7272+ )
7373+6574 @staticmethod
6675 def toxicity(filter_group, toxicity_type: str, comparison: str, value: float):
6776 if toxicity_type not in TOXICITY:
6877 raise ValueError(f"Invalid toxicity_type. Must be one of {TOXICITY}")
6978 MLNode._validate_comparison(comparison)
7079 MLNode._validate_probability(value)
7171-7272- return filter_group.add_filter({
7373- "toxicity_analysis": [toxicity_type, comparison, value]
7474- })
7575-8080+8181+ return filter_group.add_filter(
8282+ {"toxicity_analysis": [toxicity_type, comparison, value]}
8383+ )
8484+7685 @staticmethod
7786 def topic(filter_group, topic_type: str, comparison: str, value: float):
7887 if topic_type not in TOPICS:
7988 raise ValueError(f"Invalid topic_type. Must be one of {TOPICS}")
8089 MLNode._validate_comparison(comparison)
8190 MLNode._validate_probability(value)
8282-8383- return filter_group.add_filter({
8484- "topic_analysis": [topic_type, comparison, value]
8585- })
8686-9191+9292+ return filter_group.add_filter(
9393+ {"topic_analysis": [topic_type, comparison, value]}
9494+ )
9595+8796 @staticmethod
8897 def emotion(filter_group, emotion: str, comparison: str, value: float):
8998 if emotion not in EMOTIONS:
9099 raise ValueError(f"Invalid emotion. Must be one of {EMOTIONS}")
91100 MLNode._validate_comparison(comparison)
92101 MLNode._validate_probability(value)
9393-9494- return filter_group.add_filter({
9595- "topic_analysis": [emotion, comparison, value]
9696- })
9797-102102+103103+ return filter_group.add_filter({"topic_analysis": [emotion, comparison, value]})
104104+98105 @staticmethod
99106 def spam(filter_group, marketing_type: str, comparison: str, value: float):
100107 if marketing_type not in SPAM_TYPE:
101108 raise ValueError(f"Invalid marketing_type. Must be one of {SPAM_TYPE}")
102109 MLNode._validate_comparison(comparison)
103110 MLNode._validate_probability(value)
104104-105105- return filter_group.add_filter({
106106- "marketing_check": [marketing_type, comparison, value]
107107- })
108108-111111+112112+ return filter_group.add_filter(
113113+ {"marketing_check": [marketing_type, comparison, value]}
114114+ )
115115+109116 @staticmethod
110117 def img_category(filter_group, img_topic: str, comparison: str, value: float):
111118 if img_topic not in CATEGORIES:
112119 raise ValueError(f"Invalid img_topic. Must be one of {CATEGORIES}")
113120 MLNode._validate_comparison(comparison)
114121 MLNode._validate_probability(value)
115115-116116- return filter_group.add_filter({
117117- "image_arbitary": [img_topic, comparison, value]
118118- })
119119-122122+123123+ return filter_group.add_filter(
124124+ {"image_arbitary": [img_topic, comparison, value]}
125125+ )
126126+120127 @staticmethod
121128 def txt_category(filter_group, txt_topic: str, comparison: str, value: float):
122129 if txt_topic not in CATEGORIES:
123130 raise ValueError(f"Invalid txt_topic. Must be one of {CATEGORIES}")
124131 MLNode._validate_comparison(comparison)
125132 MLNode._validate_probability(value)
126126-127127- return filter_group.add_filter({
128128- "text_arbitary": [txt_topic, comparison, value]
129129- })133133+134134+ return filter_group.add_filter(
135135+ {"text_arbitary": [txt_topic, comparison, value]}
136136+ )
+27-18
pasturepy/nodes/text.py
···11-from pasturepy.constants.fields import TEXT_FIELDS, OPTION_FIELDS
11+from pasturepy.constants.fields import OPTION_FIELDS, TEXT_FIELDS
22from pasturepy.constants.graze_json import REGEX_METHODS, WORD_METHODS
3344-class TextNode:
5455+class TextNode:
66 @staticmethod
77 def _validate_field(field: str) -> None:
88 if field not in (TEXT_FIELDS | OPTION_FIELDS):
···1010 f"Invalid text field '{field}'. "
1111 f"Must be one of: {', '.join(sorted(TEXT_FIELDS | OPTION_FIELDS))}"
1212 )
1313-1313+1414 @staticmethod
1515- def word_list(filter_group, method: str, field: str, terms: list,
1616- ignore_case: bool = True, regex_list: bool = False):
1515+ def word_list(
1616+ filter_group,
1717+ method: str,
1818+ field: str,
1919+ terms: list,
2020+ ignore_case: bool = True,
2121+ regex_list: bool = False,
2222+ ):
1723 if method not in WORD_METHODS:
1818- raise ValueError(f"Invalid method '{method}'. Must be one of {WORD_METHODS}")
2424+ raise ValueError(
2525+ f"Invalid method '{method}'. Must be one of {WORD_METHODS}"
2626+ )
1927 TextNode._validate_field(field)
2020-2121- return filter_group.add_filter({
2222- method: [field, terms, ignore_case, regex_list]
2323- })
2424-2828+2929+ return filter_group.add_filter(
3030+ {method: [field, terms, ignore_case, regex_list]}
3131+ )
3232+2533 @staticmethod
2626- def regex(filter_group, method: str, field: str, term: str,
2727- ignore_case: bool = True):
3434+ def regex(
3535+ filter_group, method: str, field: str, term: str, ignore_case: bool = True
3636+ ):
2837 if method not in REGEX_METHODS:
2929- raise ValueError(f"Invalid method '{method}'. Must be one of {REGEX_METHODS}")
3838+ raise ValueError(
3939+ f"Invalid method '{method}'. Must be one of {REGEX_METHODS}"
4040+ )
3041 TextNode._validate_field(field)
3131-3232- return filter_group.add_filter({
3333- method: [field, term, ignore_case]
3434- })4242+4343+ return filter_group.add_filter({method: [field, term, ignore_case]})