# countname.py
# Written by Todd Wareham for CS 2500
"""
Given the name of an annotated textfile ofch each proper name (consisting of a
 first name followed by a last name) is surroundeed by tags "<PN>" and "</PN>"
 as a command-line argument, prints number of proper names in file.
"""

import sys
import re

    
if len(sys.argv) != 2:
    print "usage: ", sys.argv[0], " name-file"
    sys.exit(1)

f = open(sys.argv[1], "r")
line = f.read()
f.close()

nameP = "([A-Z][a-z]+ [A-Z][a-z]+)"
r = re.compile("<PN>" + nameP + "</PN>")
print ">>>", r.subn("\1", line)[1], "proper name(s) in given file"
