Spaces:
Sleeping
Sleeping
Create XML_to_HTML.py
Browse files- XML_to_HTML.py +32 -0
XML_to_HTML.py
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import re
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
def NER_XML_to_HTML(xml):
|
| 5 |
+
html = re.sub(r'WORK_OF_ART','WORKOFART',xml)
|
| 6 |
+
|
| 7 |
+
# replace every end tag with end span tag "</span>"
|
| 8 |
+
html = re.sub(r'</[A-Z]+>','</span>',html)
|
| 9 |
+
|
| 10 |
+
# replace every start tag with the appropriate css class
|
| 11 |
+
html = re.sub(r'<PERS>','<span class="ner_pers" data-entity="PERS">',html)
|
| 12 |
+
html = re.sub(r'<GROUP>','<span class="ner_group" data-entity="NORP">',html)
|
| 13 |
+
html = re.sub(r'<OCC>','<span class="ner_occ" data-entity="OCC">',html)
|
| 14 |
+
html = re.sub(r'<ORG>','<span class="ner_org" data-entity="ORG">',html)
|
| 15 |
+
html = re.sub(r'<LOC>','<span class="ner_loc" data-entity="LOC">',html)
|
| 16 |
+
html = re.sub(r'<GPE>','<span class="ner_gpe" data-entity="GPE">',html)
|
| 17 |
+
html = re.sub(r'<FAC>','<span class="ner_fac" data-entity="FAC">',html)
|
| 18 |
+
html = re.sub(r'<EVENT>','<span class="ner_event" data-entity="EVENT">',html)
|
| 19 |
+
html = re.sub(r'<DATE>','<span class="ner_date" data-entity="DATE">',html)
|
| 20 |
+
html = re.sub(r'<TIME>','<span class="ner_time" data-entity="TIME">',html)
|
| 21 |
+
html = re.sub(r'<CARDINAL>','<span class="ner_cardinal" data-entity="CARDINAL">',html)
|
| 22 |
+
html = re.sub(r'<ORDINAL>','<span class="ner_ordinal" data-entity="ORDINAL">',html)
|
| 23 |
+
html = re.sub(r'<PERCENT>','<span class="ner_percent" data-entity="PERCENT">',html)
|
| 24 |
+
html = re.sub(r'<QUANTITY>','<span class="ner_quantity" data-entity="QUANTITY">',html)
|
| 25 |
+
html = re.sub(r'<UNIT>','<span class="ner_unit" data-entity="UNIT">',html)
|
| 26 |
+
html = re.sub(r'<MONEY>','<span class="ner_money" data-entity="MONEY">',html)
|
| 27 |
+
html = re.sub(r'<CURR>','<span class="ner_currency" data-entity="CURRENCY">',html)
|
| 28 |
+
html = re.sub(r'<LANGUAGE>','<span class="ner_language" data-entity="LANGUAGE">',html)
|
| 29 |
+
html = re.sub(r'<PRODUCT>','<span class="ner_product" data-entity="PRODUCT">',html)
|
| 30 |
+
html = re.sub(r'<WORKOFART>','<span class="ner_work_of_art" data-entity="WORK_OF_ART">',html)
|
| 31 |
+
html = re.sub(r'<LAW>','<span class="ner_law" data-entity="LAW">',html)
|
| 32 |
+
return html
|