Search Results

Search found 4 results on 1 pages for 'martlark'.

Page 1/1 | 1 

  • Unexpected Blank lines in python output

    - by Martlark
    I have a bit of code that runs through a dictionary and outputs the values from it in a CSV format. Strangely I'm getting a couple of blank lines where all the output of all of the dictionary entries is blank. I've read the code and can't understand has anything except lines with commas can be output. The blank line should have values in it, so extra \n is not the cause. Can anyone advise why I'd be getting blank lines? Other times I run the missing line appears. Missing line: 6415, 6469, -4.60, clerical, 2, ,,,joe,030193027org,joelj,030155640dup Using python 2.6.5 Bit of code: tfile = file(path, 'w') tfile.write('Rec_ID_A, Rec_ID_B, Weight, Assigned, Run, By, On, Comment\n') rec_num_a = 0 while (rec_num_a <= max_rec_num_a): try: value = self.dict['DA'+str(rec_num_a)] except: value = [0,0,0,'rejected'] if (value[3]!='rejected'): weightValue = "%0.2f" % value[2] line = value[0][1:] + ', ' + value[1][1:] + ', ' + weightValue \ + ', ' + str(value[3]) + ', ' + str(value[4]) if (len(value)>5): line = line + ', ' + value[5] + ',' + value[6] + ',' + value[7] (a_pkey, b_pkey) = self.derive_pkeys(value) line = line + a_pkey + b_pkey tfile.write( line + '\n') rec_num_a +=1 Sample output 6388, 2187, 76.50, clerical, 1, ,,,cameron,030187639org,cameron,030187639org 6398, 2103, 70.79, clerical, 1, ,,,caleb,030189225org,caldb,030189225dup 6402, 2205, 1.64, clerical, 2, ,,,jenna,030190334org,cameron,020305169dup 6409, 7892, 79.09, clerical, 1, ,,,liam,030191863org,liam,030191863org 6416, 11519, 79.09, clerical, 1, ,,,thomas,030193156org,thomas,030193156org 6417, 8854, 6.10, clerical, 2, ,,,ruby,030193713org,mia,020160397org 6421, 2864, -0.84, clerical, 2, ,,,kristin,030194394org,connou,020023478dup 6423, 413, 75.63, clerical, 1, ,,,adrian,030194795org,adriah,030194795dup

    Read the article

  • Python performance improvement request for winkler

    - by Martlark
    I'm a python n00b and I'd like some suggestions on how to improve the algorithm to improve the performance of this method to compute the Jaro-Winkler distance of two names. def winklerCompareP(str1, str2): """Return approximate string comparator measure (between 0.0 and 1.0) USAGE: score = winkler(str1, str2) ARGUMENTS: str1 The first string str2 The second string DESCRIPTION: As described in 'An Application of the Fellegi-Sunter Model of Record Linkage to the 1990 U.S. Decennial Census' by William E. Winkler and Yves Thibaudeau. Based on the 'jaro' string comparator, but modifies it according to whether the first few characters are the same or not. """ # Quick check if the strings are the same - - - - - - - - - - - - - - - - - - # jaro_winkler_marker_char = chr(1) if (str1 == str2): return 1.0 len1 = len(str1) len2 = len(str2) halflen = max(len1,len2) / 2 - 1 ass1 = '' # Characters assigned in str1 ass2 = '' # Characters assigned in str2 #ass1 = '' #ass2 = '' workstr1 = str1 workstr2 = str2 common1 = 0 # Number of common characters common2 = 0 #print "'len1', str1[i], start, end, index, ass1, workstr2, common1" # Analyse the first string - - - - - - - - - - - - - - - - - - - - - - - - - # for i in range(len1): start = max(0,i-halflen) end = min(i+halflen+1,len2) index = workstr2.find(str1[i],start,end) #print 'len1', str1[i], start, end, index, ass1, workstr2, common1 if (index > -1): # Found common character common1 += 1 #ass1 += str1[i] ass1 = ass1 + str1[i] workstr2 = workstr2[:index]+jaro_winkler_marker_char+workstr2[index+1:] #print "str1 analyse result", ass1, common1 #print "str1 analyse result", ass1, common1 # Analyse the second string - - - - - - - - - - - - - - - - - - - - - - - - - # for i in range(len2): start = max(0,i-halflen) end = min(i+halflen+1,len1) index = workstr1.find(str2[i],start,end) #print 'len2', str2[i], start, end, index, ass1, workstr1, common2 if (index > -1): # Found common character common2 += 1 #ass2 += str2[i] ass2 = ass2 + str2[i] workstr1 = workstr1[:index]+jaro_winkler_marker_char+workstr1[index+1:] if (common1 != common2): print('Winkler: Wrong common values for strings "%s" and "%s"' % \ (str1, str2) + ', common1: %i, common2: %i' % (common1, common2) + \ ', common should be the same.') common1 = float(common1+common2) / 2.0 ##### This is just a fix ##### if (common1 == 0): return 0.0 # Compute number of transpositions - - - - - - - - - - - - - - - - - - - - - # transposition = 0 for i in range(len(ass1)): if (ass1[i] != ass2[i]): transposition += 1 transposition = transposition / 2.0 # Now compute how many characters are common at beginning - - - - - - - - - - # minlen = min(len1,len2) for same in range(minlen+1): if (str1[:same] != str2[:same]): break same -= 1 if (same > 4): same = 4 common1 = float(common1) w = 1./3.*(common1 / float(len1) + common1 / float(len2) + (common1-transposition) / common1) wn = w + same*0.1 * (1.0 - w) return wn

    Read the article

  • Python faster way to read fixed length fields form a file into dictionary

    - by Martlark
    I have a file of names and addresses as follows (example line) OSCAR ,CANNONS ,8 ,STIEGLITZ CIRCUIT And I want to read it into a dictionary of name and value. Here self.field_list is a list of the name, length and start point of the fixed fields in the file. What ways are there to speed up this method? (python 2.6) def line_to_dictionary(self, file_line,rec_num): file_line = file_line.lower() # Make it all lowercase return_rec = {} # Return record as a dictionary for (field_start, field_length, field_name) in self.field_list: field_data = file_line[field_start:field_start+field_length] if (self.strip_fields == True): # Strip off white spaces first field_data = field_data.strip() if (field_data != ''): # Only add non-empty fields to dictionary return_rec[field_name] = field_data # Set hidden fields # return_rec['_rec_num_'] = rec_num return_rec['_dataset_name_'] = self.name return return_rec

    Read the article

  • richfaces suggestionBox passing additional values to backing bean

    - by Martlark
    When using the rich faces suggestionBox how can you pass more than one id or value from the page with the text input to the suggestionBox backing bean. ie: to show a list of suggested cities within a selected state? Here is my autoComplete method. public List< Suburb > autocomplete(Object suggest) { String pref = (String) suggest; ArrayList< Suburb > result = new ArrayList< Suburb >(); Iterator< Suburb > iterator = getSuburbs().iterator(); while( iterator.hasNext() ) { Suburb elem = ((Suburb) iterator.next()); if( (elem.getName() != null && elem.getName().toLowerCase().indexOf( pref.toLowerCase() ) == 0) || "".equals( pref ) ) { result.add( elem ); } } return result; } As you can see there is one value passed from the page, Object suggest, which is the text of the h:inputText (in the faceLets m:textFormRow ) <m:textFormRow id="suburb" label="#{msgs.suburbPrompt}" property="#{bean[dto].addressDTO.suburb}" required="true" maxlength="100" size="30" /> <rich:suggestionbox height="200" width="200" usingSuggestObjects="true" suggestionAction="#{suburbsMBean.autocomplete}" var="suburb" for="suburb" fetchValue="#{suburb.name}" id="suggestion"> <h:column> <h:outputText value="#{suburb.name}" /> </h:column> </rich:suggestionbox> Earlier in the page you can select a state which I'd like to use to pare down the list of suburbs that the suggestion box displays.

    Read the article

1