User:GeneaBot/Code/object title
< User:GeneaBot | Code
# -*- coding: utf-8 -*-
import pywikibot
from object_display import *
from object_item import *
class Title(Item):
# Class defining a noble title on Wikidata
#
# Item Fields :
# self.ident : identifier in Wikidata (Qxxxx)
# self.item : dictionnary of labels, descriptions, statements from Wikidata
# self.comment : comment of item
# self.claimsWanted :
# self.claims : list of claims of item
#
# Fields :
#
# Item Methods :
# self.__repr__ ()
# self.__str__ ()
# self.AddClaim (pProperty, pValue, pReferences=[], pQualifiers=[])
#
# Methods :
# self.__init__ (ident, claimsWanted)
#
# static attributes :
#
ClaimsRequired = [ \
[ 'P31', 'Q5737899' ] # instance of = hereditary title
]
#
# static methods :
# Title.Get (Ident, claimsWanted, claimsRequired, source)
#
#
#
def Get(ident, claimsWanted, source):
DisplayMessages.call("O", "Title." + ident + ".Get", 4, "ident=" + str(ident))
DisplayMessages.debug("O", "Title." + ident + ".Get", 2, "ident=" + ident + ", list=" + str(Item.ListIdent))
if ident in Item.ListIdent:
item = Item.List[ident]
item.AddClaimsWanted(claimsWanted, source)
else:
item = Title(ident, claimsWanted, source)
return item
Get = staticmethod(Get)
#
#
#
#
#
def __init__(self, ident, claimsWanted, source):
DisplayMessages.call("O", "Title." + ident + ".__init__", 4, "ident=" + ident + ", claimsWanted=" + str(claimsWanted) + ", source=" + repr(source) )
Item.__init__(self, ident, claimsWanted, Title.ClaimsRequired, source)
def testTitle(NumTest, Format, Run, Ident, listClaimsWanted, source):
print( "" )
print( "---------------------------" )
text = "test " + str(NumTest) + ":\n"
text += "testTitle(Ident=" + Ident + \
", listClaimsWanted=" + str(listClaimsWanted) + \
", source=" + repr(source) + ")"
print( text )
print( "" )
dictClaimsWanted = dict()
for claimWanted in listClaimsWanted:
Property = claimWanted[0]
Value = claimWanted[1]
if not Property in dictClaimsWanted:
dictClaimsWanted[Property]= []
dictClaimsWanted[Property].append(Value)
DisplayMessages.debug("T", "testTitle", 7, "dictClaimsWanted=" + str(dictClaimsWanted) )
localTitle = Title.Get(Ident, dictClaimsWanted, source)
print( localTitle.display(Format, Run) )
print( "" )
def mainTestTitle(*args):
param = CallParameter(*args)
NumCase = param.GetValue('case', 0)
Display = param.GetValue('display', 'short')
DisplayMessages.SetFileName("")
ListDisplay = Display.split(':')
Format = ListDisplay[0]
if len(ListDisplay) >= 2:
Run = ListDisplay[1]
else:
Run = 'simu'
source = Source()
if NumCase == 0 or NumCase == 1:
testTitle(1, Format, Run, 'Q21123038', [['P460','Q21513679'], ['P279', 'Q3519259'], ['P361','Q612322'] ], source)
if NumCase == 0 or NumCase == 2:
testTitle(2, Format, Run, 'Q21513679', [['P460','Q21123038'], ['P279','Q21101501'], ['P361','Q612322'] ], source)
DisplayMessages.End()
if __name__ == "__main__":
mainTestTitle()