Ceri Stagg avatar Ceri Stagg committed 34d272f

Latest svmlight.py

Comments (0)

Files changed (1)

svmlight/svmlight.py

 
     returnval = Unpackdata( words, doc_label, queryid, slackid, costfactor )
     return returnval
-}
 
 class DOCLISTDATA(Structure):
-	_fields_ = [("label", c_double),
+	_fields_ = [("docs", POINTER(DOC)),
 		    ("totwords",  c_int),
 		    ("totdoc",  c_int)]
+
 # ----------------------------------------------
 
 def unpack_doclist( doclist, doclistdata ):
 
      (max_docs, max_words) = count_doclist( doclist )
 
+     templist = []
      totwords = 0
      for item in doc_iterator:
 	     unpackdata = unpack_document( item, max_words )
 			     totwords = candidatewords
 
 	     docnum = unpackdata.doc_label
-	     bla
+	     
 	     newdoc = DOC()
 	     newdoc.docnum = docnum
 	     newdoc.queryid = unpackdata.queryid
 	     newdoc.costfactor = unpackdata.costfactor
 	     newdoc.slackid = unpackdata.slackid
+	     newdoc.fvec = create_svector( unpackdata.words, "", 1.0 )
+	     templist.append( newdoc )
 
+     totdoc = len( doclist )
 
-	     class DOC(Structure):
-    _fields_ = [("docnum",     c_long),
-                ("queryid",    c_long),
-                ("costfactor", c_double),
-                ("slackid",    c_long),
-                ("fvec",       POINTER(SVECTOR))]
+     carray = ( DOC * totdoc )()
+     counter = 0
+     for item in iter( templist ):
+	     carray[ counter ] = item
+	     counter += 1
 
-doc_label queryid slackid costfactor numwords
+     result = DOCLISTDATA()
 
+     result.docs = pointer( carray )
+     result.totwords = totwords
+     result.totdoc = totdoc
+     
+     return result
 # ----------------------------------------------
 
 def generate_C_string_from_python( pythonstring ):
 	cstring = ( c_char * len( pythonstring ) )()
 	cstring[:] = pythonstring
 	return cstring
-
 # ----------------------------------------------
 
 def create_fixed_size_words( words ):
 	result.words = pointer( cwords )
 	svm.sprod_ss( result, result )
 
-	result.userdefined = def generate_C_string_from_python( userdefined )
+	result.userdefined = generate_C_string_from_python( userdefined )
 	result.factor = factor
 	result.kernel_id = 0
 	result.next = 0
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.