dynamic-learning-model 2.0.1__tar.gz → 2.1.5__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: dynamic-learning-model
3
- Version: 2.0.1
3
+ Version: 2.1.5
4
4
  Summary: A Dynamic Learning Model for processing NLP queries using hybrid AI and reasoning.
5
5
  Home-page: https://github.com/VigneshT24/Dynamic_Learning_Model
6
6
  Author: Vignesh Thondikulam
@@ -23,7 +23,8 @@ class DLM:
23
23
  __unsure_while_thinking = False # if uncertain while thinking, then it will let the user know that
24
24
  __nlp_similarity_value = None # saves the similarity value by doing SpaCy calculation (for debugging)
25
25
  __special_stripped_query = None # saves query without any special words for reduced interference while vector calculating
26
- __nltk_names = set(name.lower() for name in names.words())
26
+ __nltk_names = set(name.lower() for name in names.words()) # list of name corpus to be identified in complex word problems
27
+ __refuse_to_respond = False # if profanity or all caps-lock frustration is detected, refuse to respond and suggest user to try again (bot respect)
27
28
 
28
29
  # personalized responses to let the user know that the bot doesn't know the answer
29
30
  __fallback_responses = [
@@ -222,8 +223,8 @@ class DLM:
222
223
  },
223
224
  "rectangle": {
224
225
  "keywords": ["area", "rectangle"],
225
- "params": ["length", "width"],
226
- "formula": lambda d: d["length"] * d["width"]
226
+ "params": ["height", "width"],
227
+ "formula": lambda d: d["height"] * d["width"]
227
228
  },
228
229
  "parallelogram": {
229
230
  "keywords": ["area", "parallelogram"],
@@ -264,8 +265,10 @@ class DLM:
264
265
  },
265
266
  "rectangular prism": {
266
267
  "keywords": ["volume", "rectangular prism"],
267
- "params": ["length", "width", "height"],
268
- "formula": lambda d: d["length"] * d["width"] * d["height"]
268
+ # "params": ["length", "width", "height"],
269
+ # "formula": lambda d: d["length"] * d["width"] * d["height"]
270
+ "params": ["height", "length", "width"],
271
+ "formula": lambda d: d["height"] * d["length"] * d["width"]
269
272
  },
270
273
  "cylinder": {
271
274
  "keywords": ["volume", "cylinder"],
@@ -334,6 +337,19 @@ class DLM:
334
337
  "quarter": 0.25, "quarters": 0.25
335
338
  }
336
339
 
340
+ # Response for when user uses profanity and all caps, indicating extreme anger
341
+ __refuse_to_respond_statements = [
342
+ "I understand you may be upset. However, I can’t respond to messages expressed in anger. Please rephrase calmly so I can assist you.",
343
+ "Your message seems written in frustration. For a constructive exchange, I need you to restate it respectfully.",
344
+ "I want to help, but I won’t respond to hostile language. Please rewrite your query in a calmer tone.",
345
+ "I can see this might be frustrating. I can’t respond while the message is written in anger, but if you rephrase, I’ll gladly help.",
346
+ "I know emotions can run high, but I need a calmer phrasing to continue. Please try rewording your question.",
347
+ "It sounds like you’re upset. Let’s take a step back — rephrase your question respectfully and I’ll do my best to answer.",
348
+ "Looks like the tone came across strongly. Please rephrase in a calmer way so I can give you the best answer.",
349
+ "I can’t respond to messages phrased in anger. Try again in a clearer, more respectful tone, and I’ll assist right away.",
350
+ "Let’s reset. Rephrase your question without the frustration, and I’ll be able to help you effectively."
351
+ ]
352
+
337
353
  def __init__(self, mode, db_filename="dlm_database.db"): # initializes SQL database & SpaCy NLP
338
354
  """
339
355
  Initialize the Dynamic-Learning Model (DLM) chatbot.
@@ -585,8 +601,8 @@ class DLM:
585
601
  Behavior:
586
602
  - Detects aggressive language using profanity filtering.
587
603
  - Analyzes punctuation and casing to infer emotional tone such as:
588
- - 'angry aggressive' for profane content
589
- - 'angry frustrated' for all-uppercase text
604
+ - 'angry aggressive' for profane content - refuse to respond
605
+ - 'angry frustrated' for all-uppercase text - refuse to respond
590
606
  - 'angry confused' for combined "?" and "!"
591
607
  - 'angry excited' for "!" only
592
608
  - 'confused unclear' for "?" only
@@ -594,20 +610,24 @@ class DLM:
594
610
  - Stores the result in self.__tone as a string label.
595
611
  """
596
612
  is_profane = profanity.contains_profanity(orig_input)
597
- if is_profane:
598
- self.__tone = "angry aggressive"
599
- elif orig_input == orig_input.upper():
600
- self.__tone = "angry frustrated"
601
- elif orig_input.__contains__("?") and orig_input.__contains__("!"):
602
- self.__tone = "angry confused"
603
- elif orig_input.__contains__("!"):
604
- self.__tone = "angry excited"
605
- elif orig_input.__contains__("?"):
606
- self.__tone = "confused unclear"
607
- elif orig_input.__contains__("...") or orig_input.__contains__(".."):
608
- self.__tone = "doubtful uncertain"
613
+ if is_profane and orig_input == orig_input.upper(): # too inappropriate to respond
614
+ self.__refuse_to_respond = True
609
615
  else:
610
- self.__tone = ""
616
+ self.__refuse_to_respond = False
617
+ if is_profane:
618
+ self.__tone = "angry aggressive"
619
+ elif orig_input == orig_input.upper():
620
+ self.__tone = "angry frustrated"
621
+ elif orig_input.__contains__("?") and orig_input.__contains__("!"):
622
+ self.__tone = "angry confused"
623
+ elif orig_input.__contains__("!"):
624
+ self.__tone = "angry excited"
625
+ elif orig_input.__contains__("?"):
626
+ self.__tone = "confused unclear"
627
+ elif orig_input.__contains__("...") or orig_input.__contains__(".."):
628
+ self.__tone = "doubtful uncertain"
629
+ else:
630
+ self.__tone = ""
611
631
 
612
632
  def __geometric_calculation(self, filtered_query, display_thought): # returns float result or None
613
633
  """
@@ -690,9 +710,13 @@ class DLM:
690
710
  break
691
711
  is_similar = difflib.get_close_matches(phrase, [obj], n=1, cutoff=0.70)
692
712
  if is_similar and is_similar[0] == obj:
693
- object_intel.extend(self.__geometric_calculation_identifiers[obj]["keywords"])
694
- end_check = True
695
- break
713
+ geom_type = self.__geometric_calculation_identifiers[obj]["keywords"]
714
+ if (lower_tokens.__contains__(geom_type[0])):
715
+ object_intel.extend(geom_type)
716
+ end_check = True
717
+ break
718
+ else:
719
+ continue
696
720
  if end_check:
697
721
  break
698
722
 
@@ -741,9 +765,13 @@ class DLM:
741
765
  try:
742
766
  if "height" in params:
743
767
  formula_inputs["height"] = height_value
768
+ if "side" in params:
769
+ formula_inputs["side"] = height_value
744
770
 
745
771
  value_idx = 0 # count how many values to be added in formula_inputs
746
772
  for param in params:
773
+ if len(other_values) < 1:
774
+ break
747
775
  if param == "height":
748
776
  continue # already added
749
777
  elif param == "other": # two consecutive numbers to append
@@ -752,7 +780,8 @@ class DLM:
752
780
  else: # only one number to append
753
781
  formula_inputs[param] = other_values[value_idx]
754
782
  value_idx += 1
755
-
783
+ if len(other_values) <= 1:
784
+ break
756
785
  # Try calculating the result and return
757
786
  result = round(formula(formula_inputs), 4)
758
787
  return result
@@ -1551,6 +1580,13 @@ class DLM:
1551
1580
  self.__query = input("Empty input is unacceptable. Please enter something: ")
1552
1581
 
1553
1582
  self.__set_sentiment_tone(self.__query) # sets global variable sentiment tone
1583
+ while self.__refuse_to_respond:
1584
+ print()
1585
+ self.__query = input(random.choice(self.__refuse_to_respond_statements) + "\nTry again: ")
1586
+ while self.__query is None or self.__query == "":
1587
+ self.__query = input("Empty input is unacceptable. Please enter something: ")
1588
+ self.__set_sentiment_tone(self.__query)
1589
+
1554
1590
 
1555
1591
  # storing the user-query (filtered, lower-case, no punctuation)
1556
1592
  if self.__mode == "compute":
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: dynamic-learning-model
3
- Version: 2.0.1
3
+ Version: 2.1.5
4
4
  Summary: A Dynamic Learning Model for processing NLP queries using hybrid AI and reasoning.
5
5
  Home-page: https://github.com/VigneshT24/Dynamic_Learning_Model
6
6
  Author: Vignesh Thondikulam
@@ -5,7 +5,7 @@ with open('README.md', 'r', encoding='utf-8') as f:
5
5
 
6
6
  setup(
7
7
  name='dynamic-learning-model',
8
- version='2.0.1',
8
+ version='2.1.5',
9
9
  author='Vignesh Thondikulam',
10
10
  author_email='vignesh.tho2006@gmail.com',
11
11
  description='A Dynamic Learning Model for processing NLP queries using hybrid AI and reasoning.',