<commit_before>#!/usr/bin/python
"""A quick usage example. 

Once voeparse is installed, this should tell you most of what you need to know
in order to start doing things with VOEvent packets.

The attributes are built from the structure of the XML file, 
so the best way to understand where the variable names come from is to simply 
open the XML packet in your favourite web browser and dig around.

See also: the slightly terse documentation at http://lxml.de/objectify.html
"""
import copy
import voeparse

xml_filename = 'tests/resources/SWIFT_bat_position_v2.0_example.xml'

v = voeparse.load(xml_filename)

#Basic attribute access
print "Ivorn:", v.attrib['ivorn']
print "Role:", v.attrib['role']
print "AuthorIVORN:", v.Who.AuthorIVORN
print "Short name:", v.Who.Author.shortName
print "Contact:", v.Who.Author.contactEmail

#Copying by value, and validation:
print "Original valid as v2.0? ", voeparse.validate_as_v2_0(v)
v_copy = copy.copy(v)
print "Copy valid? ", voeparse.validate_as_v2_0(v_copy)

#Changing values:
v_copy.Who.Author.shortName = 'BillyBob'
v_copy.attrib['role'] = 'test'
print "Changes valid? ", voeparse.validate_as_v2_0(v_copy)

v_copy.attrib['role'] = 'flying circus'
print "How about now? ", voeparse.validate_as_v2_0(v_copy)
print "But the original is ok, because we copied? ", voeparse.validate_as_v2_0(v)

v.Who.BadPath = "This new child certainly won't conform with the schema."
assert voeparse.validate_as_v2_0(v) == False
del v.Who.BadPath
assert voeparse.validate_as_v2_0(v) == True<commit_msg>Update example<commit_after>#!/usr/bin/python
"""A quick usage example. 

Once voeparse is installed, this should tell you most of what you need to know
in order to start doing things with VOEvent packets.

The attributes are built from the structure of the XML file, 
so the best way to understand where the variable names come from is to simply 
open the XML packet in your favourite web browser and dig around.

See also: the slightly terse documentation at http://lxml.de/objectify.html
"""
import copy
import voeparse

xml_filename = 'tests/resources/SWIFT_bat_position_v2.0_example.xml'

v = voeparse.load(xml_filename)

#Basic attribute access
print "Ivorn:", v.attrib['ivorn']
print "Role:", v.attrib['role']
print "AuthorIVORN:", v.Who.AuthorIVORN
print "Short name:", v.Who.Author.shortName
print "Contact:", v.Who.Author.contactEmail

#Copying by value, and validation:
print "Original valid as v2.0? ", voeparse.valid_as_v2_0(v)
v_copy = copy.copy(v)
print "Copy valid? ", voeparse.valid_as_v2_0(v_copy)

#Changing values:
v_copy.Who.Author.shortName = 'BillyBob'
v_copy.attrib['role'] = 'test'
print "Changes valid? ", voeparse.valid_as_v2_0(v_copy)

v_copy.attrib['role'] = 'flying circus'
print "How about now? ", voeparse.valid_as_v2_0(v_copy)
print "But the original is ok, because we copied? ", voeparse.valid_as_v2_0(v)

v.Who.BadPath = "This new child certainly won't conform with the schema."
assert voeparse.valid_as_v2_0(v) == False
del v.Who.BadPath
assert voeparse.valid_as_v2_0(v) == True
#######################################################
# And now, SCIENCE
#######################################################
c = voeparse.pull_astro_coords(v)
print "Coords:", c
{'fraction_non_alphanumeric': 0.1379950495049505, 'fraction_numerical': 0.011138613861386138, 'mean_word_length': 5.6114519427402865, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 8}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1152915', 'n_tokens_mistral': 1101, 'n_tokens_neox': 1081, 'n_words': 338}