示例#1
0
    def processFields(self, fields):	
	walscodeindex = None
	glottologrefindex = None
	isbnindex = None
	for i, cell in enumerate(fields[0]):
	    if cell.strip() == 'walscode':
		walscodeindex = i
		continue
	    if cell.strip() == 'glottologref':
		glottologrefindex = i
		continue
	    if cell.strip() == 'isbn':		
		isbnindex = i
		continue
	if walscodeindex == None:
	    return 
	for l in fields[1:]:
	    walscode = l[walscodeindex] 
	    glottologref = False
	    isbnref = False
	    self.dictionary[walscode] = {}
	    if glottologrefindex:
		glottologrefcode = l[glottologrefindex].strip().lower()
		if glottologrefcode.startswith('r'):
		    glottologrefcode = glottologrefcode[1:]
		try:
		    int(glottologrefcode)
		    glottologref = "glottolog:r%s" % glottologrefcode
		except:
		    pass 
	    self.dictionary[walscode]['glottologref'] =  glottologref
	    if isbnindex:
		isbnrefcode = l[isbnindex]
		if isbnrefcode != '':
		    isbnref = "<urn:isbn:%s>" % isbnrefcode
	    self.dictionary[walscode]['isbnref'] = isbnref
	     
	    self.dictionary[walscode]['values'] = {}
	    walsfeatures =  getWalsFeatures() 
	    for i,value in enumerate(l):
		if i == 0:
		    continue
		if value:
		    try:
			value = str(int(value))
		    except ValueError:
			continue
		    featurenumber = fields[0][i].strip().upper()
		    if featurenumber.startswith('F'):
			featurenumber = featurenumber[1:]   
		    if featurenumber not in walsfeatures:  
			continue 
		    if value not in walsfeatures[featurenumber]: 
			continue
		    try:
			self.dictionary[walscode]['values'][featurenumber] = int(value)
		    except TypeError:
			pass
		    except ValueError:
			pass 
示例#2
0
    def processFields(self, fields):
        walscodeindex = None
        glottologrefindex = None
        isbnindex = None
        for i, cell in enumerate(fields[0]):
            if cell.strip() == 'walscode':
                walscodeindex = i
                continue
            if cell.strip() == 'glottologref':
                glottologrefindex = i
                continue
            if cell.strip() == 'isbn':
                isbnindex = i
                continue
        if walscodeindex == None:
            return
        for l in fields[1:]:
            walscode = l[walscodeindex]
            glottologref = False
            isbnref = False
            self.dictionary[walscode] = {}
            if glottologrefindex:
                glottologrefcode = l[glottologrefindex].strip().lower()
                if glottologrefcode.startswith('r'):
                    glottologrefcode = glottologrefcode[1:]
                try:
                    int(glottologrefcode)
                    glottologref = "glottolog:r%s" % glottologrefcode
                except:
                    pass
            self.dictionary[walscode]['glottologref'] = glottologref
            if isbnindex:
                isbnrefcode = l[isbnindex]
                if isbnrefcode != '':
                    isbnref = "<urn:isbn:%s>" % isbnrefcode
            self.dictionary[walscode]['isbnref'] = isbnref

            self.dictionary[walscode]['values'] = {}
            walsfeatures = getWalsFeatures()
            for i, value in enumerate(l):
                if i == 0:
                    continue
                if value:
                    try:
                        value = str(int(value))
                    except ValueError:
                        continue
                    featurenumber = fields[0][i].strip().upper()
                    if featurenumber.startswith('F'):
                        featurenumber = featurenumber[1:]
                    if featurenumber not in walsfeatures:
                        continue
                    if value not in walsfeatures[featurenumber]:
                        continue
                    try:
                        self.dictionary[walscode]['values'][
                            featurenumber] = int(value)
                    except TypeError:
                        pass
                    except ValueError:
                        pass
示例#3
0
	    return False
	
	for row_entry in feed.entry: 
	    dico = gdata.spreadsheet.text_db.Record(row_entry=row_entry).content 
	    d = {} 
	    walscode = dico['wals'] 
	    self.dictionary[walscode] = {}
	    self.dictionary[walscode]['glottologref'] = False
	    self.dictionary[walscode]['isbnref'] = False 
	    self.dictionary[walscode]['values'] = {}
	    for k in dico:
		try:		
		    featurenumber = k.upper()
		    if featurenumber.startswith('F'):
			featurenumber = featurenumber[1:] 
		    if featurenumber.upper() not in getWalsFeatures():
			continue		    
		    featurevalue = int(dico[k]) 
		except ValueError:
		    continue
		except TypeError:
		    continue 
		self.dictionary[walscode]['values'][featurenumber] = featurevalue
	write2db(self.dictionary,self.creator,self.dataset)
	self.dumpRDF()
	 
	
    def fromXLS(self, xlsfile, creator, originalfilename = False): 
	self.creator = creator	
	self.dataset = xlsfile.split('/')[-1]
	if originalfilename:
示例#4
0
        for row_entry in feed.entry:
            dico = gdata.spreadsheet.text_db.Record(
                row_entry=row_entry).content
            d = {}
            walscode = dico['wals']
            self.dictionary[walscode] = {}
            self.dictionary[walscode]['glottologref'] = False
            self.dictionary[walscode]['isbnref'] = False
            self.dictionary[walscode]['values'] = {}
            for k in dico:
                try:
                    featurenumber = k.upper()
                    if featurenumber.startswith('F'):
                        featurenumber = featurenumber[1:]
                    if featurenumber.upper() not in getWalsFeatures():
                        continue
                    featurevalue = int(dico[k])
                except ValueError:
                    continue
                except TypeError:
                    continue
                self.dictionary[walscode]['values'][
                    featurenumber] = featurevalue
        write2db(self.dictionary, self.creator, self.dataset)
        self.dumpRDF()

    def fromXLS(self, xlsfile, creator, originalfilename=False):
        self.creator = creator
        self.dataset = xlsfile.split('/')[-1]
        if originalfilename: