Jump to content

Wikipedia talk:WikiProject Astronomical objects/Starbox catalog disambiguation.py

Page contents not supported in other languages.
From Wikipedia, the free encyclopedia
import re
import sys
import string

def starbox_catalog_disambiguation(s):
	"""
	Argument is article text.

	Returns a list consisting of (1) new article text and (2) a 
	human-readable summary of the changes made.
	"""
	#
	# List of acronyms and what they should disambiguate to
	#
	changes = [
['ADS', 'Aitken Double Star Catalogue'],
['AG', 'Astronomische Gesellschaft Katalog'],
['BD', 'Durchmusterung'],
['CCDM', 'Catalog of Components of Double and Multiple Stars'],
['CD', 'Durchmusterung'],
['CEL', 'Celescope Catalogue of Ultraviolet Magnitudes'], # redlink
				# cf. http://adsabs.harvard.edu/abs/1973SAOSR.350....1D
['CPD', 'Durchmusterung'],
['CSI', 'Catalog of Stellar Identifications'],   # redlink
['FK4', 'Fourth Fundamental Catalogue'],
['FK5', 'Fifth Fundamental Catalogue'],
['GC', 'Boss General Catalogue'],
['GCTP', 'General Catalogue of Trigonometric Parallaxes'],
['GSC', 'Guide Star Catalog'],
['HD', 'Henry Draper Catalogue'],
['HIC', 'Hipparcos Input Catalogue'], # redlink
['HIP', 'Hipparcos Catalogue'],
['HR', 'Bright Star Catalogue'],
['IDS', 'Index Catalogue of Visual Double Stars'],
['LFT', 'Luyten Five-Tenths catalogue'],
['LHS', 'Luyten Half-Second catalogue'],
['LTT', 'Luyten Two-Tenths catalogue'],
['N30', 'Catalog of 5,268 Standard Stars Based on the Normal System N30'], # redlink
                              # cf. http://cdsarc.u-strasbg.fr/viz-bin/Cat?I/80
['NLTT', 'New Luyten Two-Tenths catalogue'],
['NSV', 'New Catalogue of Suspected Variable Stars'],   # redlink
['PHL', 'Palomar-Haro-Luyten catalogue'], # redlink
['PLX', 'General Catalogue of Trigonometric Parallaxes'],
['PMC', 'Tokyo Photoelectric Meridian Circle Catalog'], # redlink
['PPM', 'PPM Star Catalogue'],
['ROT', 'Catalogue of Rotational Velocities of the Stars'], # redlink
					# cf. http://adsabs.harvard.edu/abs/1970crvs.book.....U
['SAO', 'Smithsonian Astrophysical Observatory Star Catalog'],
['TD1', 'TD1 Catalog of Stellar Ultraviolet Fluxes'],   # redlink
['TYC', 'Tycho Catalogue'],
['UBV', 'UBV Photoelectric Catalogue'], # redlink
                            # cf. http://adsabs.harvard.edu/abs/1968PUSNO..21....0B
['WDS', 'Washington Double Star Catalog']
	]
#
# Partial list of redlinked acronyms left as is:
#
# GCRV (General Catalogue of Stellar Radial Velocities)
# JP11
# MSX5C
# uvby98 (uvbyβ photoelectric photometric catalogue)
#
# Partial list of bluelinked acronyms that are left as is:
#
# AAVSO (article is on the organization that generated this database)
# 2MASS (destination article correct)
# EUVE (article is on the satellite that generated this catalog)
# IRAS (article is on the satellite that generated this catalog)
#
	r = re.compile(r'({{Starbox catalog[^}]*}})')
	ans = r.split(s)
	summary = ''
	for i in range((len(ans)-1)/2):
		j=2*i+1
		newansj = ans[j]
		for k in changes:
			newansj = newansj.replace('[['+k[0]+']]', '[['+k[1]+'|'+k[0]+']]')
		if (newansj != ans[j]):
			summary = summary + 'Disambiguated\n' + ans[j] + '\n\nto\n' + newansj + '\n.\n'
			ans[j] = newansj	
	newstr = ''
	for q in ans:
		newstr += q
	return [newstr, summary]

#
# Main program: tests starbox_catalog_disambiguation() function
#
# Article input name=arg 1, output name=arg 2
n1=sys.argv[1]
n2=sys.argv[2]
f1=open(n1,'r')
f2=open(n2,'w')
edits=starbox_catalog_disambiguation(f1.read())
f1.close()
print 'Edits:\n'
print edits[1]
f2.write(edits[0])
f2.close()
#