INNER CODE UNIT · Python

TrainingData

center-for-threat-informed-defense/tram · src/scripts/reformat_training_data.py:204

class TrainingData(object):
    def __init__(self):
        self.mappings = {}  # Mapping is sentence text plus a list of Attack IDs

    def add_mapping(self, sentence_text, attack_id=None):
        mappings = self.mappings.get(sentence_text, [])  # Get mappings or empty list

        if attack_id:  # If attack_id is specified, add it to the list
            if attack_id not in mappings:
                mappings.append(attack_id)

        self.mappings[sentence_text] = mappings  # Put the mapping list back in

    def to_report_export_serializer_json(self):
        """Creates a dict that can be used to create
        a serializers.ReportExportSerializer instance
        """
        utc_now = datetime.utcnow().isoformat() + "Z"

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…