Exemplo n.º 1
0
 def _attempt_to_commit(name, level, statute):
     if (level == "misdemeanor class a"
             or level == "felony class c") and "attempt to commit" in name:
         question_string = "Was the underlying conduct a sex crime?"
         charge_type_by_level = ChargeClassifier._classification_by_level(
             level, statute).ambiguous_charge_type[0]
         options = {"Yes": SexCrime(), "No": charge_type_by_level}
         return ChargeClassifier._build_ambiguous_charge_type_with_question(
             question_string, options)
     if level == "felony class b" and "attempt to commit" in name:
         question_string = "Was this a drug-related charge?"
         drug_crime_question_string = "Was the underlying substance marijuana?"
         drug_crime_options = {
             "Yes": MarijuanaEligible(),
             "No": FelonyClassB()
         }
         drug_crime_classification = ChargeClassifier._build_ambiguous_charge_type_with_question(
             drug_crime_question_string, drug_crime_options)
         drug_crime_question_id = f"{question_string}-Yes-{drug_crime_classification.question.question_id}"  # type: ignore
         drug_crime_question = replace(drug_crime_classification.question,
                                       question_id=drug_crime_question_id)
         charge_types = drug_crime_classification.ambiguous_charge_type + [
             PersonFelonyClassB()
         ]
         question = Question(
             question_string,
             question_string,
             {
                 "Yes":
                 Answer(question=drug_crime_question),
                 "No":
                 Answer(edit={"charge_type": PersonFelonyClassB.__name__}),
             },
         )
         return AmbiguousChargeTypeWithQuestion(charge_types, question)
Exemplo n.º 2
0
 def _manufacture_delivery(name, level, statute):
     if any([
             manu_del_keyword in name
             for manu_del_keyword in ["delivery", "manu/del", "manufactur"]
     ]):
         if any([
                 schedule_2_keyword in name for schedule_2_keyword in
             ["2", "ii", "heroin", "cocaine", "meth"]
         ]):
             if level == "Felony Unclassified":
                 question_string = "Was the charge for an A Felony or B Felony?"
                 options = {
                     "A Felony": FelonyClassA(),
                     "B Felony": FelonyClassB()
                 }
                 return ChargeClassifier._build_ambiguous_charge_type_with_question(
                     question_string, options)
         elif any([
                 schedule_3_keyword in name
                 for schedule_3_keyword in ["3", "iii", "4", " iv"]
         ]):
             return ChargeClassifier._classification_by_level(
                 level, statute)
         else:
             # The name contains either a "1" or no schedule number, and thus is possibly a marijuana charge.
             question_string = "Was the underlying substance marijuana?"
             charge_types_with_question = ChargeClassifier._classification_by_level(
                 level, statute)
             if level == "Felony Unclassified":
                 felony_unclassified_question_id = (
                     f"{question_string}-No-{charge_types_with_question.question.question_id}"
                 )
                 felony_unclassified_question = replace(
                     charge_types_with_question.question,
                     question_id=felony_unclassified_question_id)
                 charge_types = [
                     MarijuanaEligible()
                 ] + charge_types_with_question.ambiguous_charge_type
                 question = Question(
                     question_string,
                     question_string,
                     {
                         "Yes":
                         Answer(edit={
                             "charge_type": MarijuanaEligible.__name__
                         }),
                         "No":
                         Answer(question=felony_unclassified_question),
                     },
                 )
                 return AmbiguousChargeTypeWithQuestion(
                     charge_types, question)
             elif level == "Felony Class A" or level == "Felony Class B":
                 charge_type = charge_types_with_question.ambiguous_charge_type[
                     0]
                 options = {"Yes": MarijuanaEligible(), "No": charge_type}
                 return ChargeClassifier._build_ambiguous_charge_type_with_question(
                     question_string, options)
Exemplo n.º 3
0
 def _handle_pcs_and_manufacture_delivery(name, level, statute,
                                          schedule_2_handler):
     if any([
             schedule_2_keyword in name for schedule_2_keyword in
         ["2", "ii", "heroin", "cocaine", "meth"]
     ]):
         return schedule_2_handler(level)
     elif any([
             schedule_3_keyword in name
             for schedule_3_keyword in ["3", "iii", "4", " iv"]
     ]):
         return ChargeClassifier._classification_by_level(level, statute)
     else:
         # The name contains either a "1" or no schedule number, and thus is possibly a marijuana charge.
         question_string = "Was the underlying substance marijuana?"
         charge_types_with_question = ChargeClassifier._classification_by_level(
             level, statute)
         if level == "felony unclassified":
             felony_unclassified_question_id = (
                 f"{question_string}-No-{charge_types_with_question.question.question_id}"
             )
             felony_unclassified_question = replace(
                 charge_types_with_question.question,
                 question_id=felony_unclassified_question_id)
             charge_types = [
                 MarijuanaManufactureDelivery()
             ] + charge_types_with_question.ambiguous_charge_type
             question = Question(
                 question_string,
                 question_string,
                 {
                     "Yes":
                     Answer(edit={
                         "charge_type":
                         MarijuanaManufactureDelivery.__name__
                     }),
                     "No":
                     Answer(question=felony_unclassified_question),
                 },
             )
             return AmbiguousChargeTypeWithQuestion(charge_types, question)
         elif level == "felony class a" or level == "felony class b":
             charge_type = charge_types_with_question.ambiguous_charge_type[
                 0]
             options = {
                 "Yes": MarijuanaManufactureDelivery(),
                 "No": charge_type
             }
             return ChargeClassifier._build_ambiguous_charge_type_with_question(
                 question_string, options)
Exemplo n.º 4
0
 def _build_option(question, ruling, question_id_prefix):
     disposition = {
         "disposition": {
             "date": "__DATE__",
             "ruling": ruling.lower()
         }
     }
     if question:
         updated_question = RecordCreator._append_edits_to_question(
             question, disposition, question_id_prefix)
         option = {ruling: Answer(question=updated_question)}
     else:
         option = {ruling: Answer(edit=disposition)}
     return option
Exemplo n.º 5
0
 def _build_probation_revoked_option(question, question_id_prefix):
     edits = {
         "disposition": {
             "date": "__DATE__",
             "ruling": "convicted"
         },
         "probation_revoked": "__PROBATION_REVOKED_DATE__",
     }
     if question:
         updated_question = RecordCreator._append_edits_to_question(
             question, edits, question_id_prefix)
         option = {"Probation Revoked": Answer(question=updated_question)}
     else:
         option = {"Probation Revoked": Answer(edit=edits)}
     return option
Exemplo n.º 6
0
 def _build_ambiguous_charge_type_with_question(
         question: str,
         options: Dict[str, ChargeType]) -> AmbiguousChargeTypeWithQuestion:
     options_dict = {}
     charge_types = []
     for key, value in options.items():
         charge_types.append(value)
         options_dict[key] = Answer(
             edit={"charge_type": value.__class__.__name__})
     return AmbiguousChargeTypeWithQuestion(
         charge_types, Question(question, question, options_dict))
Exemplo n.º 7
0
 def _build_case(
     oeci_case: OeciCase, new_charges: List[Charge]
 ) -> Tuple[AmbiguousCase, List[QuestionSummary]]:
     ambiguous_charges: List[AmbiguousCharge] = []
     questions: List[QuestionSummary] = []
     for oeci_charge in oeci_case.charges:
         ambiguous_charge_id = oeci_charge.ambiguous_charge_id
         charge_dict = {
             "name": oeci_charge.name,
             "statute": oeci_charge.statute,
             "level": oeci_charge.level,
             "date": oeci_charge.date,
             "disposition": oeci_charge.disposition,
             "probation_revoked": oeci_charge.probation_revoked,
             "balance_due_in_cents": oeci_charge.balance_due_in_cents,
             "case_number": oeci_case.summary.case_number,
             "violation_type": oeci_case.summary.violation_type,
             "birth_year": oeci_case.summary.birth_year,
             "edit_status": EditStatus(oeci_charge.edit_status),
         }
         if oeci_charge.disposition.status == DispositionStatus.UNKNOWN:
             charge_dict.pop("disposition")
             ambiguous_charge_dismissed, question_dismissed = ChargeCreator.create(
                 ambiguous_charge_id,
                 **charge_dict,
                 disposition=DispositionCreator.create(
                     date_class.today(), "dismissed"),
             )
             ambiguous_charge_convicted, question_convicted = ChargeCreator.create(
                 ambiguous_charge_id,
                 **charge_dict,
                 disposition=DispositionCreator.create(
                     date_class.future(), "convicted"),
             )
             if RecordCreator._disposition_question_is_irrelevant(
                     ambiguous_charge_convicted,
                     ambiguous_charge_dismissed):
                 ambiguous_charges.append(ambiguous_charge_dismissed)
                 question = RecordCreator._append_ambiguous_charge_id_to_question_id(
                     question_dismissed, ambiguous_charge_id
                 ) if question_dismissed else None  # type: ignore # TODO: Fix type
             else:
                 ambiguous_charges.append(ambiguous_charge_dismissed +
                                          ambiguous_charge_convicted)
                 disposition_question_text = "Choose the disposition"
                 question_id_prefix = ambiguous_charge_id + disposition_question_text
                 dismissed_option = RecordCreator._build_option(
                     question_dismissed, "Dismissed",
                     f"{question_id_prefix}-dismissed")
                 convicted_option = RecordCreator._build_option(
                     question_convicted, "Convicted",
                     f"{question_id_prefix}-convicted")
                 probation_revoked_option = RecordCreator._build_probation_revoked_option(
                     question_convicted, f"{question_id_prefix}-revoked")
                 unknown_option = {"Unknown": Answer()}
                 question = Question(
                     question_id_prefix,
                     disposition_question_text,
                     {
                         **dismissed_option,
                         **convicted_option,
                         **probation_revoked_option,
                         **unknown_option
                     },
                 )
         else:
             ambiguous_charge, maybe_question = ChargeCreator.create(
                 ambiguous_charge_id, **charge_dict)
             ambiguous_charges.append(ambiguous_charge)
             question = RecordCreator._append_ambiguous_charge_id_to_question_id(
                 maybe_question, ambiguous_charge_id
             ) if maybe_question else None  # type: ignore # TODO: Fix type
         if question:
             question_summary = QuestionSummary(
                 ambiguous_charge_id, oeci_case.summary.case_number,
                 question)
             questions.append(question_summary)
     ambiguous_charges += [[charge] for charge in new_charges]
     ambiguous_case: AmbiguousCase = []
     for charges in product(*ambiguous_charges):
         possible_case = Case(oeci_case.summary, charges=tuple(charges))
         ambiguous_case.append(possible_case)
     return ambiguous_case, questions