def add_fact(self,<EOL>fact_term_name,<EOL>fact_term_attribute,<EOL>fact_dt_name='<STR_LIT>',<EOL>fact_dt_namespace_name=None,<EOL>fact_dt_namespace_uri=DINGOS_NAMESPACE_URI,<EOL>fact_dt_kind=FactDataType.UNKNOWN_KIND,<EOL>values=None,<EOL>value_iobject_id=None,<EOL>value_iobject_ts=None,<EOL>node_id_name='<STR_LIT>',<EOL>is_attribute=False,<EOL>ns_uri_dict=None,<EOL>namespaces=None,<EOL>top_level_namespace=None):
if not values:<EOL><INDENT>values = []<EOL><DEDENT>if not namespaces:<EOL><INDENT>namespaces = []<EOL><DEDENT>if not ns_uri_dict:<EOL><INDENT>ns_uri_dict = None<EOL><DEDENT>fact_term, created = get_or_create_fact_term(iobject_family_name=self.iobject_family.name,<EOL>fact_term_name=fact_term_name,<EOL>fact_term_attribute=fact_term_attribute,<EOL>iobject_type_name=self.iobject_type.name,<EOL>iobject_type_namespace_uri=self.iobject_type.namespace.uri,<EOL>fact_dt_name=fact_dt_name,<EOL>fact_dt_kind=fact_dt_kind,<EOL>fact_dt_namespace_name=fact_dt_namespace_name,<EOL>fact_dt_namespace_uri=fact_dt_namespace_uri,<EOL>dingos_class_map=self._DCM)<EOL>fact_obj, created = get_or_create_fact(fact_term,<EOL>fact_dt_name=fact_dt_name,<EOL>fact_dt_namespace_uri=fact_dt_namespace_uri,<EOL>values=values,<EOL>value_iobject_id=value_iobject_id,<EOL>value_iobject_ts=value_iobject_ts,<EOL>)<EOL>node_id, created = dingos_class_map['<STR_LIT>'].objects.get_or_create(name=node_id_name)<EOL>node_id_name_components = node_id_name.split('<STR_LIT::>')<EOL>attributed_io2f = None<EOL>if node_id_name_components[-<NUM_LIT:1>] and node_id_name_components[-<NUM_LIT:1>][<NUM_LIT:0>] == '<STR_LIT:A>':<EOL><INDENT>attributed_node_id_name = "<STR_LIT::>".join(node_id_name_components[:-<NUM_LIT:1>])<EOL>try:<EOL><INDENT>attributed_io2f = dingos_class_map['<STR_LIT>'].objects.get(iobject=self,<EOL>node_id__name=attributed_node_id_name)<EOL><DEDENT>except InfoObject2Fact.DoesNotExist:<EOL><INDENT>pass<EOL><DEDENT><DEDENT>io2f = self._DCM['<STR_LIT>'].objects.create(<EOL>node_id=node_id,<EOL>iobject=self,<EOL>fact=fact_obj,<EOL>attributed_fact=attributed_io2f)<EOL>counter = <NUM_LIT:0><EOL>io2f2n_list = []<EOL>namespace_map_elts = FactTermNamespaceMap.objects.filter(fact_term=fact_term).order_by('<STR_LIT:id>','<STR_LIT>').values_list('<STR_LIT:id>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>')<EOL>namespace_maps = []<EOL>for k,g in itertools.groupby(namespace_map_elts,lambda x:x[<NUM_LIT:0>]):<EOL><INDENT>namespace_maps.append(list(g))<EOL><DEDENT>namespace_map = None<EOL>namespaces_uris = map(lambda x:x[<NUM_LIT:0>],namespaces)<EOL>for i in namespace_maps:<EOL><INDENT>if namespaces_uris == map(lambda x:x[<NUM_LIT:2>],i):<EOL><INDENT>namespace_map = FactTermNamespaceMap.objects.get(id=i[<NUM_LIT:0>][<NUM_LIT:0>])<EOL>break<EOL><DEDENT><DEDENT>if not namespace_map:<EOL><INDENT>namespace_map = FactTermNamespaceMap.objects.create(fact_term=fact_term)<EOL>for (ns_uri,ns_slug) in namespaces:<EOL><INDENT>if ns_uri:<EOL><INDENT>if not (ns_uri in ns_uri_dict):<EOL><INDENT>ns_uri_obj, created = self._DCM['<STR_LIT>'].objects.get_or_create(uri=ns_uri,defaults={'<STR_LIT:name>':ns_slug})<EOL>ns_uri_obj_pk = ns_uri_obj.pk<EOL>ns_uri_dict[ns_uri]=ns_uri_obj_pk<EOL><DEDENT>else:<EOL><INDENT>ns_uri_obj_pk = ns_uri_dict[ns_uri]<EOL><DEDENT>io2f2n_list.append(PositionalNamespace(fact_term_namespace_map=namespace_map,position=counter,namespace_id=ns_uri_obj_pk))<EOL><DEDENT>counter +=<NUM_LIT:1><EOL><DEDENT>if len(io2f2n_list)!= <NUM_LIT:0>:<EOL><INDENT>PositionalNamespace.objects.bulk_create(io2f2n_list)<EOL><DEDENT>else:<EOL><INDENT>namespace_map.delete()<EOL>namespace_map = None<EOL><DEDENT><DEDENT>if namespace_map:<EOL><INDENT>io2f.namespace_map = namespace_map<EOL>io2f.save()<EOL><DEDENT>return io2f<EOL>
Add a fact to the iobject. If a fact term for the iobject type
with the given fact data type and source (CYBOX, etc.) does not
exist yet, it is created.