diff --git a/src/tests/python/data/ccl03.xml b/src/tests/python/data/ccl03.xml new file mode 100644 index 0000000000000000000000000000000000000000..d9e41b11ffeaa4d27489aa945ca48ddb31f140aa --- /dev/null +++ b/src/tests/python/data/ccl03.xml @@ -0,0 +1,16 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE chunkList SYSTEM "ccl.dtd"> +<chunkList> + <chunk id="ch1"> + <sentence id="s1"> + <tok> + <orth>Kofeina</orth> + <lex disamb="1"><base>kofeina</base><ctag>subst:sg:nom:f</ctag></lex> + <prop key="e01">http://plwordnet.pwr.wroc.pl/wordnet/synset/15470</prop> + <prop key="sense:ukb:syns_id">15470</prop> + <prop key="sense:ukb:syns_rank">15470/30.0403943450</prop> + <prop key="sense:ukb:unitsstr">kofeina.1(24:sbst)</prop> + </tok> + </sentence> + </chunk> +</chunkList> diff --git a/src/tests/python/test_remove_attr.py b/src/tests/python/test_remove_attr.py new file mode 100644 index 0000000000000000000000000000000000000000..fdc79d0b3c2f80ad54cbe0eda09b401a1a235041 --- /dev/null +++ b/src/tests/python/test_remove_attr.py @@ -0,0 +1,39 @@ +import cclutils as ccl + + +def remove_attribute(token, key): + """ + Remove attribute of a token. + + Args: + token (Corpus2.token) + key (object): Attribute name, automatically casted to string. + + Returns: + bool value informing about the status of the removal operation: `True` if + attribute has been removed. If token has no specified key or any + metadata at all, `False` will be returned. + """ + if token.has_metadata(): + metadata = token.get_metadata() + return metadata.remove_attribute(key) + return False + + +test_doc = "data/ccl03.xml" +rm_prop = "e01" +doc = ccl.read(test_doc) + +tok = [ + t for p in doc.paragraphs() for s in p.sentences() for t in s.tokens() +].pop() + +# initial check +assert ccl.get_attribute(tok, rm_prop) == "http://plwordnet.pwr.wroc.pl/wordnet/synset/15470" + +# test +assert remove_attribute(tok, rm_prop) == True +assert remove_attribute(tok, "not-existing-prop") == False +assert ccl.get_attribute(tok, rm_prop, None) == None + +print("All tests passed!")