<commit_before>from cybox.objects.address_object import Address
from cybox.objects.uri_object import URI
from cybox.objects.email_message_object import EmailMessage
from cybox.objects.file_object import File
from cybox.objects.win_registry_key_object import WinRegistryKey
from cybox.objects.win_process_object import WinProcess
from cybox.objects.win_service_object import WinService
from cybox.objects.process_object import Process
from cybox.objects.domain_name_object import DomainName
from cybox.objects.mutex_object import Mutex
from cybox.objects.network_connection_object import NetworkConnection
from cybox.objects.win_executable_file_object import WinExecutableFile
from cybox.objects.archive_file_object import ArchiveFile

from stix2elevator.vocab_mappings import *
from stix2elevator.ids import *

import stixmarx

from stix2.pattern_expressions import ComparisonExpression, BooleanExpression, CompoundObservableExpression, ParentheticalExpression
from stix2.constants import (FloatConstant, HashConstant, IntegerConstant, ListConstant, StringConstant)

import re
from six import text_type
import sys
if sys.version_info > (3,):
    long = int

KEEP_OBSERVABLE_DATA_USED_IN_PATTERNS = False

KEEP_INDICATORS_USED_IN_COMPOSITE_INDICATOR_EXPRESSION = True


class ComparisonExpressionForElevator(ComparisonExpression):
    def contains_placeholder(self):
        return isinstance(self.rhs, IdrefPlaceHolder)

    def collapse_reference(self, prefix):
        parts_of_lhs = self.lhs.split(":")
        new_lhs = prefix + "." + parts_of_lhs[1]
        return ComparisonExpressionForElevator(self.operator, new_lhs, self.rhs)

    def replace_placeholder_with_idref_pattern(self, idref):
        if isinstance(self.rhs, IdrefPlaceHolder):
            change_made, pattern = self.rhs.replace_placeholder_with_idref_pattern(idref)
            if change_made:
                return True, pattern.collapse_reference(self.lhs)
        return False, self

    def partition_according_to_object_path(self):
        return self

    def contains_unconverted_term(self):
        return False


class BooleanExpressionForElevator(BooleanExpression):

    def add_operand(self, operand):
        self.operands.append(operand)

    def contains_placeholder(self):
        for args in self.operands:<commit_msg>Handle Constants and ObjectPaths<commit_after>from cybox.objects.address_object import Address
from cybox.objects.uri_object import URI
from cybox.objects.email_message_object import EmailMessage
from cybox.objects.file_object import File
from cybox.objects.win_registry_key_object import WinRegistryKey
from cybox.objects.win_process_object import WinProcess
from cybox.objects.win_service_object import WinService
from cybox.objects.process_object import Process
from cybox.objects.domain_name_object import DomainName
from cybox.objects.mutex_object import Mutex
from cybox.objects.network_connection_object import NetworkConnection
from cybox.objects.win_executable_file_object import WinExecutableFile
from cybox.objects.archive_file_object import ArchiveFile

from stix2elevator.vocab_mappings import *
from stix2elevator.ids import *

import stixmarx

from stix2.pattern_expressions import ComparisonExpression, BooleanExpression, CompoundObservableExpression, ParentheticalExpression
from stix2.constants import (Constant, FloatConstant, HashConstant, IntegerConstant, ListConstant, StringConstant)
from stix2.object_path import ObjectPath

import re
from six import text_type
import sys
if sys.version_info > (3,):
    long = int

KEEP_OBSERVABLE_DATA_USED_IN_PATTERNS = False

KEEP_INDICATORS_USED_IN_COMPOSITE_INDICATOR_EXPRESSION = True


class ComparisonExpressionForElevator(ComparisonExpression):
    # overrides, so IdrefPlaceHolder can be handled
    def __init__(self, operator, lhs, rhs, negated=False):
        if operator == "=" and isinstance(rhs, ListConstant):
            self.operator = "IN"
        else:
            self.operator = operator
        if isinstance(lhs, ObjectPath):
            self.lhs = lhs
        else:
            self.lhs = ObjectPath.make_object_path(lhs)
        if isinstance(rhs, Constant) or isinstance(rhs, IdrefPlaceHolder):
            self.rhs = rhs
        else:
            self.rhs = make_constant(rhs)
        self.negated = negated
        self.root_type = self.lhs.object_type_name

    def contains_placeholder(self):
        return isinstance(self.rhs, IdrefPlaceHolder)

    def collapse_reference(self, prefix):
        new_lhs = prefix.merge(self.lhs)
        return ComparisonExpressionForElevator(self.operator, new_lhs, self.rhs)

    def replace_placeholder_with_idref_pattern(self, idref):
        if isinstance(self.rhs, IdrefPlaceHolder):
            change_made, pattern = self.rhs.replace_placeholder_with_idref_pattern(idref)
            if change_made:
                return True, pattern.collapse_reference(self.lhs)
        return False, self

    def partition_according_to_object_path(self):
        return self

    def contains_unconverted_term(self):
        return False


class BooleanExpressionForElevator(BooleanExpression):

    def add_operand(self, operand):
        self.operands.append(operand)

    def contains_placeholder(self):
        for args in self.operands:
{'fraction_non_alphanumeric': 0.05974962063732929, 'fraction_numerical': 0.002276176024279211, 'mean_word_length': 4.550526315789473, 'pattern_counts': {'":': 1, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7465315', 'n_tokens_mistral': 1517, 'n_tokens_neox': 1498, 'n_words': 345}