How to use is_a method in Sure

Best Python code snippet using sure_python

element.py

Source:element.py Github

copy

Full Screen

1def get_psets(element):2 psets = {}3 try:4 if element.is_a("IfcTypeObject"):5 if element.HasPropertySets:6 for definition in element.HasPropertySets:7 psets[definition.Name] = get_property_definition(definition)8 else:9 for relationship in element.IsDefinedBy:10 if relationship.is_a("IfcRelDefinesByProperties"):11 definition = relationship.RelatingPropertyDefinition12 psets[definition.Name] = get_property_definition(definition)13 except Exception as e:14 import traceback15 print("failed to load properties: {}".format(e))16 traceback.print_exc()17 return psets18def get_property_definition(definition):19 if definition is not None:20 props = {}21 if definition.is_a("IfcElementQuantity"):22 props.update(get_quantities(definition.Quantities))23 elif definition.is_a("IfcPropertySet"):24 props.update(get_properties(definition.HasProperties))25 else:26 # Entity introduced in IFC427 # definition.is_a('IfcPreDefinedPropertySet'):28 for prop in range(4, len(definition)):29 props[definition.attribute_name(prop)] = definition[prop]30 return props31def get_quantities(quantities):32 results = {}33 for quantity in quantities:34 if quantity.is_a("IfcPhysicalSimpleQuantity"):35 results[quantity.Name] = quantity[3]36 return results37def get_properties(properties):38 results = {}39 for prop in properties:40 if prop.is_a("IfcPropertySingleValue"):41 results[prop.Name] = prop.NominalValue.wrappedValue if prop.NominalValue else None42 elif prop.is_a("IfcComplexProperty"):43 data = prop.get_info()44 data["properties"] = get_properties(prop.HasProperties)45 del data["HasProperties"]46 results[prop.Name] = data47 return results48def get_type(element):49 if hasattr(element, "IsTypedBy") and element.IsTypedBy:50 return element.IsTypedBy[0].RelatingType51 elif hasattr(element, "IsDefinedBy") and element.IsDefinedBy: # IFC2X352 for relationship in element.IsDefinedBy:53 if relationship.is_a("IfcRelDefinesByType"):54 return relationship.RelatingType55def get_material(element):56 if hasattr(element, "HasAssociations") and element.HasAssociations:57 for relationship in element.HasAssociations:58 if relationship.is_a("IfcRelAssociatesMaterial"):59 if relationship.RelatingMaterial.is_a("IfcMaterialLayerSetUsage"):60 return relationship.RelatingMaterial.ForLayerSet61 elif relationship.RelatingMaterial.is_a("IfcMaterialProfileSetUsage"):62 return relationship.RelatingMaterial.ForProfileSet63 return relationship.RelatingMaterial64 relating_type = get_type(element)65 if hasattr(relating_type, "HasAssociations") and relating_type.HasAssociations:66 for relationship in relating_type.HasAssociations:67 if relationship.is_a("IfcRelAssociatesMaterial"):68 if relationship.RelatingMaterial.is_a("IfcMaterialLayerSetUsage"):69 return relationship.RelatingMaterial.ForLayerSet70 elif relationship.RelatingMaterial.is_a("IfcMaterialProfileSetUsage"):71 return relationship.RelatingMaterial.ForProfileSet72 return relationship.RelatingMaterial73def get_container(element):74 if hasattr(element, "ContainedInStructure") and element.ContainedInStructure:75 return element.ContainedInStructure[0].RelatingStructure76def replace_attribute(element, old, new):77 for i, attribute in enumerate(element):78 if attribute == old:79 element[i] = new80 elif isinstance(attribute, tuple):81 new_attribute = list(attribute)82 for j, item in enumerate(attribute):83 if item == old:84 new_attribute[j] = new85 element[i] = new_attribute86def is_representation_of_context(representation, context, subcontext=None, target_view=None):87 if target_view is not None:88 return (89 representation.ContextOfItems.is_a("IfcGeometricRepresentationSubContext")90 and representation.ContextOfItems.TargetView == target_view91 and representation.ContextOfItems.ContextIdentifier == subcontext92 and representation.ContextOfItems.ContextType == context93 )94 elif subcontext is not None:95 return (96 representation.ContextOfItems.is_a("IfcGeometricRepresentationSubContext")97 and representation.ContextOfItems.ContextIdentifier == subcontext98 and representation.ContextOfItems.ContextType == context99 )100 elif representation.ContextOfItems.ContextType == context:101 return True102def remove_deep(ifc_file, element):103 subgraph = list(ifc_file.traverse(element))104 subgraph_set = set(subgraph)105 for ref in subgraph[::-1]:106 if ref.id() and len(set(ifc_file.get_inverse(ref)) - subgraph_set) == 0:107 ifc_file.remove(ref)108def get_representation(element, context, subcontext=None, target_view=None):109 if element.is_a("IfcProduct") and element.Representation:110 for r in element.Representation.Representations:111 if is_representation_of_context(r, context, subcontext, target_view):112 return r113 elif element.is_a("IfcTypeProduct") and element.RepresentationMaps:114 for r in element.RepresentationMaps:115 if is_representation_of_context(r.MappedRepresentation, context, subcontext, target_view):...

Full Screen

Full Screen

utils.py

Source:utils.py Github

copy

Full Screen

...16 elif isinstance(c, Restriction):17 i_r = getattr(i, c.property.name)18 if i_r:19 if c.type == 24:20 return is_a(c.value, i_r)21 if c.type == 25:22 return is_a(i_r, c.value)23 elif c.type == 29:24 return c.value == i_r[0]25 else:26 return False27 else:28 if i.INDIRECT_is_instance_of:29 if c in i.INDIRECT_is_instance_of:30 return True31 else:32 # for y in i.INDIRECT_is_instance_of:33 # if y not in exclude:34 # if is_a(y, c, exclude):35 # return True36 # else:37 # exclude.add(y)38 # else:39 return False40 else:41 return False42def not_instance_of(x, c, exclude=set()):43 class not_c(Thing):44 equivalent_to = [Not(c)]45 return is_instance_of(x, c, exclude)46def is_a(x, c, exclude=set()):47 if x == c or c == Thing:48 return True49 elif hasattr(x, 'is_a') and c in x.is_a:50 return True51 elif hasattr(x, 'INDIRECT_is_a'):52 if c in x.INDIRECT_is_a:53 return True54 # else:55 # for b in x.INDIRECT_is_a:56 # if hasattr(c, 'INDIRECT_is_a') and b in c.INDIRECT_is_a:57 # pass58 # if b != x and b != Thing:59 # if is_a(b, c):60 # return True61 if isinstance(c, And):62 return all(is_a(x, cc) for cc in c.Classes)63 elif isinstance(c, (IndividualValueList, list)):64 return x in c65 if isinstance(x, Or):66 return all(is_a(cc, c) for cc in x.Classes)67 elif isinstance(x, OneOf):68 return all(is_instance_of(xi, c) for xi in x.instances)69 elif isinstance(x, And):70 return any(is_a(xi, c) for xi in x.Classes)71 else:72 # for y in x.is_a:73 # if hasattr(y, 'is_a') and y not in exclude:74 # if is_a(y, c, exclude):75 # return True76 # else:77 # exclude = exclude.add(y)78 # else:79 return False80def not_a(x, c, exclude=set()):81 class not_c(Thing):82 equivalent_to = [Not(c)]83 return is_a(x, c, exclude)84def inf(As, C=None):85 # inf elements of As86 if C:87 As = [A for A in As if not is_a(C, A)]88 return inf(As)89 else:90 As = list(As)91 for _ in range(len(As)):92 A = As.pop(0)93 if not any(is_a(B, A) for B in As if hasattr(B,'is_a') and hasattr(B, 'INDIRECT_is_a')):94 As.append(A)95 return As96def sup(As, C=None):97 # sup elements of As not containing C98 if C:99 As = [A for A in As if not is_a(C, A)]100 return sup(As)101 else:102 As = list(As)103 for _ in range(len(As)):104 A = As.pop(0)105 if not any(is_a(A, B) for B in As):106 As.append(A)107 return As108def pretty(x):109 if hasattr(x, 'name'):110 return x.name111 elif isinstance(x, Restriction):112 if x.type in {29, 24}:113 return x.property.name + x.value.name114 else:...

Full Screen

Full Screen

Ontology.py

Source:Ontology.py Github

copy

Full Screen

1# -*- coding: utf-8 -*-2from owlready2 import *34print("ONTOLOGY\n")5onto = get_ontology("videoteca.owl").load()67# print the main content of ontology8print("Class list in ontology:\n")9print(list(onto.classes()), "\n")1011#print the object properties12print("Object property in ontology:\n")13print(list(onto.object_properties()), "\n")1415#print the data properties16print("Data property in ontology:\n")17print(list(onto.data_properties()), "\n")1819#print the individuals20print("Customer list in ontology:\n")21customers = onto.search(is_a = onto.Customer)22print(customers, "\n")2324print("Salesperson list in ontology:\n")25salesperson = onto.search(is_a = onto.Salesperson)26print(salesperson, "\n")2728print("Actor list in ontology:\n")29actors = onto.search(is_a = onto.Actor)30print(actors, "\n")3132print("Movie list in ontology:\n")33movies = onto.search(is_a = onto.Movie)34print(movies, "\n")3536print("Director list in ontology:\n")37directors = onto.search(is_a = onto.Director)38print(directors, "\n")3940print("Format list in ontology:\n")41formats = onto.search(is_a = onto.Format)42print(formats, "\n")4344print("Genre list in ontology:\n")45genres = onto.search(is_a = onto.Genre)46print(genres, "\n")4748print("Shelf list in ontology:\n")49shelfs = onto.search(is_a = onto.Shelf)50print(shelfs, "\n")5152print("Shop list in ontology:\n")53shops = onto.search(is_a = onto.Shop)54print(shops, "\n")5556#example queries57print("List of movies in DVD format:\n")58film = onto.search(is_a = onto.Movie, hasFormat = onto.search(is_a = onto.DVD))59print(film, "\n")6061print("List of comedy films:\n")62film = onto.search(is_a = onto.Movie, hasGenre = onto.search(is_a = onto.Comedy))63print(film, "\n")646566676869 ...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Sure automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful