-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstring_utilities.py
More file actions
66 lines (53 loc) · 1.8 KB
/
Copy pathstring_utilities.py
File metadata and controls
66 lines (53 loc) · 1.8 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import re
def count(sequence, item):
return sum([1 for elem in sequence if elem == item])
def enclose(string):
if string.find('http://') > -1:
return '<'+string.strip()+'>'
else:
return mapLangString(string)
#return string
def escapeAmpersandCharacter(string):
return string.replace('&','&')
def escapeBracketCharacter(string):
string = string.replace('(','')
string = string.replace(')', '')
return string
def escapeApostropheCharacter(string):
return string.replace('\'','_')
def escapeForwardSlashCharacter(string):
return string.replace('/','_')
def mapEnclose(string):
if count(re.split('[:// ,]',string),'http') > 1:
return ', '.join(map(enclose,string.split(',')))
else:
return enclose(string)
def mapLangString(string):
string = string.replace('"','')
if len(re.split('[;,]',string)) > 1:
return ', '.join(map(langString,re.split('[;,]',string)))
else:
return langString(string)
def processString(string):
string = escapeAmpersandCharacter(string)
string = toUnicode(string)
return string
def langString(string):
# This checks if the object value is in the format :skos_concept_name
# and prevents further double quotes or @ to be concatenated to it.
if string.find(':') > -1:
return string
string = string.strip()
if string.find('@') > 0:
string = string.replace('@','"@')
else:
string = string + '"'
return '"' + string
def generateXMLTagName(string):
string = toUnicode(string)
string = escapeBracketCharacter(string)
string = escapeApostropheCharacter(string)
string = escapeForwardSlashCharacter(string)
return (string.lower()).replace(' ','_')
def toUnicode(string):
return string.encode('utf-8').strip()