-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
49 lines (38 loc) · 1.65 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# Import libraries
import xml.etree.ElementTree as etree
# Specify XML file name
xml_file = 'business_glossary_xml_sample.xml'
# Parse the XML file
tree = etree.parse(xml_file)
# Define the XML namespace.
namespace = {'bg': 'http://www.ibm.com/is/bg/importexport'}
# Find all synonymGroup elements.
synonym_groups = tree.findall('.//bg:synonymGroup', namespace)
# Count the number of synonymGroup elements.
SG = len(synonym_groups)
# Count the number of term elements.
terms = tree.findall('.//bg:term', namespace)
T = len(terms)
# Count the number of terms in the synonymGroup elements.
synonyms = tree.findall('.//bg:synonymGroup/bg:synonyms/bg:termRef', namespace)
TS = len(synonyms)
# Count the number of terms labelled "type hierarchy dummy"
dummy_terms = [term for term in terms if term.find(".//bg:label[@name='type hierarchy dummy']", namespace) is not None]
DT = len(dummy_terms)
# Calculate the number of concepts
C = SG + T - TS - DT
print(f'There are {SG} synonymGroups. (SG)')
print(f'There are {T} terms. (T)')
print(f'There are {TS} synonyms. (TS)')
print(f'There are {DT} dummy terms. (DT)')
print(f'We are expecting {C} concepts. (C)')
# Count the number of category elements.
categories = tree.findall('.//bg:category', namespace)
Ca = len(categories)
# Count the number of category elements having a name attribute equal to "Individual Concepts"
IC = len([category for category in categories if category.get('name') == 'Individual Concepts'])
# Calculate the number of dictionaries
D = Ca - IC
print(f'There are {Ca} categories. (Ca)')
print(f'There are {IC} categories named "Individual Concepts". (IC)')
print(f'We are expecting {D} dictionaries. (D)')