Ceri Stagg avatar Ceri Stagg committed 51c63b4

Refactor creation of DOC examples

Comments (0)

Files changed (1)

svmlight/svmlight.py

     return returnval
 # ----------------------------------------------
 
+def create_example(docnum, queryid, slackid, costfactor, fvec):
+    result = DOC()
+    
+    result.docnum = docnum
+    result.queryid = queryid
+    result.slackid = slackid
+    result.costfactor = costfactor
+    result.fvec = fvec
+
+    return result
+# ----------------------------------------------
+
+def create_example(unpackdata, fvec):
+    return create_example( unpackdata.doc_label, unpackdata.queryid, unpackdata.slackid, unpackdata.costfactor, fvec )
+# ----------------------------------------------
+
 class DOCLISTDATA(Structure):
     _fields_ = [("docs", POINTER(DOC)),
             ("totwords",  c_int),
                 totwords = candidatewords
 
         docnum = unpackdata.doc_label
-         
-        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 )
+     
+        fvec = create_svector( unpackdata.words, "", 1.0 )
+        newdoc = create_example( unpackdata, fvec )
         templist.append( newdoc )
 
     totdoc = len( doclist )
     return result
 # ----------------------------------------------
 
-'''
-DOC *create_example(long docnum, long queryid, long slackid, 
-
-            double costfactor, SVECTOR *fvec)
-
-{
-
-  DOC *example;
-  example = (DOC *)my_malloc(sizeof(DOC));
-  example->docnum=docnum;
-  example->queryid=queryid;
-  example->slackid=slackid;
-  example->costfactor=costfactor;
-  example->fvec=fvec;
-
-  return(example);
-
-}
-'''
-# ----------------------------------------------
-
 def print_client_data( client_data ):
     verbosity = client_data.pverb
     learn_parm = client_data.plearn
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.