-
Notifications
You must be signed in to change notification settings - Fork 1
/
mappingFormats.py
42 lines (34 loc) · 1.25 KB
/
mappingFormats.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
from xml.sax.saxutils import quoteattr
def get_file_header():
return """<?xml version=\"1.0\" encoding=\"utf-8\"?>
<rdf:RDF xmlns="http://knowledgeweb.semanticweb.org/heterogeneity/alignment"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:xsd="http://www.w3.org/2001/XMLSchema#">
<Alignment>
<xml>yes</xml>
<level>0</level>
<type>??</type>"""
def get_mapping_format(source, target,relation , measure):
return """
<map>
<Cell>
<entity1 rdf:resource=%s/>
<entity2 rdf:resource=%s/>
<relation>%s</relation>
<measure rdf:datatype="xsd:float">%.1f</measure>
</Cell>
</map>""" %(quoteattr(source), quoteattr(target), relation, float(measure))
#(quoteattr(source), quoteattr(target), relation, measure)
def _get_file_footer():
return """
</Alignment>
</rdf:RDF>
"""
def write_Mappings(file, mapping):
#df=pd.read_csv(alignments)
#df=df.drop_duplicates(subset=['Class_Name_1', 'Class_Name_2'], keep='first')
with open(file, 'w', encoding='utf-8') as Myfile:
Myfile.write(get_file_header())
for source, target, relation, measure in mapping:
Myfile.write(get_mapping_format(source, target, relation, measure))
Myfile.write(_get_file_footer())