From: "mohammad siddiqui" <writetosafi@hotmail.com>
To: skaller@users.sourceforge.net
Cc: rich@annexia.org, caml-list@inria.fr
Subject: [Caml-list] sscanf help
Date: Sun, 18 Apr 2004 03:59:17 +0000 [thread overview]
Message-ID: <BAY7-F39GA9jq8lUrrk00056a79@hotmail.com> (raw)
Hello,
I am having hardtime dealing with sscanf and fscanf fucntion. I am actually
converting code from C to OCAML. The functions uses multiple sscanf
fucntions. I have no clue how to deal with this. Can anyone please help me
out?
Attached is the function in C. The application is used for text
classification.
i
nt parse_document(char *line, DOC *doc, double *label,
long int *numwords, long int max_words_doc)
{
register long wpos,pos;
long wnum;
double weight;
int numread;
char featurepair[1000],junk[1000];
doc->queryid=0;
doc->costfactor=1;
pos=0;
while(line[pos]) { /* cut off comments */
if(line[pos] == '#') {
line[pos]=0;
}
else {
pos++;
}
}
wpos=0;
if(sscanf(line,"%lf",label) == EOF) return(0);
pos=0;
while(isspace((int)line[pos])) pos++;
while((!isspace((int)line[pos])) && line[pos]) pos++;
while(((numread=sscanf(line+pos,"%s",featurepair)) != EOF) &&
(wpos<max_words_doc)) {
/* printf("%s\n",featurepair); */
while(isspace((int)line[pos])) pos++;
while((!isspace((int)line[pos])) && line[pos]) pos++;
if(sscanf(featurepair,"qid:%ld%s",&wnum,junk)==1) {
/* it is the query id */
doc->queryid=(long)wnum;
}
else if(sscanf(featurepair,"cost:%lf%s",&weight,junk)==1) {
/* it is the example-dependent cost factor */
doc->costfactor=(double)weight;
}
else if(sscanf(featurepair,"%ld:%lf%s",&wnum,&weight,junk)==2) {
/* it is a regular feature */
if(wnum<=0) {
perror ("Feature numbers must be larger or equal to 1!!!\n");
printf("LINE: %s\n",line);
exit (1);
}
if((wpos>0) && ((doc->words[wpos-1]).wnum >= wnum)) {
perror ("Features must be in increasing order!!!\n");
printf("LINE: %s\n",line);
exit (1);
}
(doc->words[wpos]).wnum=wnum;
(doc->words[wpos]).weight=(FVAL)weight;
wpos++;
}
else {
perror ("Cannot parse feature/value pair!!!\n");
printf("'%s' in LINE: %s\n",featurepair,line);
exit (1);
}
}
(doc->words[wpos]).wnum=0;
(*numwords)=wpos+1;
doc->docnum=-1;
doc->twonorm_sq=sprod_ss(doc->words,doc->words);
return(1);
}
thanks,
Mohammad S Siddiqui.
_________________________________________________________________
MSN Toolbar provides one-click access to Hotmail from any Web page FREE
download! http://toolbar.msn.com/go/onm00200413ave/direct/01/
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
next reply other threads:[~2004-04-18 3:59 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-04-18 3:59 mohammad siddiqui [this message]
2004-04-20 9:56 ` Pierre Weis
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=BAY7-F39GA9jq8lUrrk00056a79@hotmail.com \
--to=writetosafi@hotmail.com \
--cc=caml-list@inria.fr \
--cc=rich@annexia.org \
--cc=skaller@users.sourceforge.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).