def get_or_create_fact(fact_term,<EOL>fact_dt_name='<STR_LIT>',<EOL>fact_dt_namespace_uri=DINGOS_NAMESPACE_URI,<EOL>values=None,<EOL>value_iobject_id=None,<EOL>value_iobject_ts=None,<EOL>):
if not values:<EOL><INDENT>values = []<EOL><DEDENT>vocab_namespace, created = dingos_class_map['<STR_LIT>'].objects.get_or_create(uri=fact_dt_namespace_uri)<EOL>fact_data_type, created = dingos_class_map['<STR_LIT>'].objects.get_or_create(name=fact_dt_name,<EOL>namespace=vocab_namespace)<EOL>value_objects = []<EOL>for value in values:<EOL><INDENT>storage_location=dingos.DINGOS_VALUES_TABLE<EOL>if value == None:<EOL><INDENT>value = '<STR_LIT>'<EOL><DEDENT>if isinstance(value,tuple):<EOL><INDENT>value, storage_location = value<EOL><DEDENT>if storage_location == dingos.DINGOS_VALUES_TABLE:<EOL><INDENT>if len(value) > dingos.DINGOS_MAX_VALUE_SIZE_WRITTEN_TO_VALUE_TABLE:<EOL><INDENT>(value_hash,storage_location) = write_large_value(value)<EOL>value = value_hash<EOL><DEDENT><DEDENT>fact_value, created = dingos_class_map['<STR_LIT>'].objects.get_or_create(value=value,<EOL>fact_data_type=fact_data_type,<EOL>storage_location=storage_location)<EOL>value_objects.append(fact_value)<EOL><DEDENT>possibly_matching_facts = Fact.objects.filter(fact_values__in=value_objects,<EOL>value_iobject_id=value_iobject_id,<EOL>value_iobject_ts=value_iobject_ts,<EOL>fact_term=fact_term<EOL>).values_list('<STR_LIT>',flat=True)<EOL>matching_facts = Fact.objects.filter(pk__in=list(possibly_matching_facts)).annotate(num_values=Count('<STR_LIT>')).filter(num_values=len(value_objects)).exclude(id__in=Fact.objects.filter(pk__in=possibly_matching_facts).annotate(total_values=Count('<STR_LIT>')).filter(total_values__gt=len(value_objects)))<EOL>created = True<EOL>try:<EOL><INDENT>fact_obj = matching_facts[<NUM_LIT:0>]<EOL>created = False<EOL>logger.debug("<STR_LIT>" % fact_obj.pk)<EOL><DEDENT>except:<EOL><INDENT>fact_obj = dingos_class_map['<STR_LIT>'].objects.create(fact_term=fact_term,<EOL>value_iobject_id=value_iobject_id,<EOL>value_iobject_ts=value_iobject_ts,<EOL>)<EOL>fact_obj.fact_values.add(*value_objects)<EOL>fact_obj.save()<EOL><DEDENT>return fact_obj, created<EOL>
Get or create a fact object.