Re: Parsing of Names
"Frédéric Gobry" <[email protected]> Fri, 18 May 2007 17:44:33 +0100
| Newsgroups | gmane.comp.gnome.apps.pybliographer |
|---|---|
| Message-ID | <[email protected]> |
> Mostly because I don't know exactly what the schema is---these are generic
> bibtex files. If I use the Reader then I have to know what the scheme is,
> correct?
Correct, or at least you need to overwrite a method to handle the
unknown fields in some way (which you need to do anyway if you want to
store them in pyblio). You could probably even bypass the schema if
you don't store in an actual pyblio store, as the validation is
performed when you do a db.add().
> author =3D "Scott McNamara, Martha Cyr, Chris Rogers and Barbara Bratzel",
>
> Isn't that an acceptable BibTex form? Does Pyblio only allow names
> separated by "and"?
No, it is not a valid BibTeX form, ie if you pass it to bibtex you
won't get what you expect. It might however be interesting to let the
reader manage these, at least in a subclass. Let me know if you are
interested in this, and we can find a way to make the author parser
more reusable (or just go ahead and make it more reusable, I accept
patches :) just keep in mind that the default implementation should
err on the safe side wrt to its understanding of BibTeX files)
>
> -Doug
>
> >>
> >> Thanks for any pointers,
> >>
> >> -Doug
> >>
> >> def parseBibtex(udir, filename, fields):
> >> """ Pass in directory, filename, and list of valid fields. """
> >> from Pyblio.Parsers.Syntax.BibTeX.Parser import read, Comment,
> >> Record, Join, Block, ATComment
> >> from Pyblio.Exceptions import ParserError
> >> fd =3D open(udir + "/" + filename, "r")
> >> try:
> >> records =3D read(fd)
> >> except ParserError, err:
> >> print "ERROR: %s at line %d: %s" % (file, err[0], err[1])
> >> return
> >> for rec in records:
> >> data =3D []
> >> if type(rec) =3D=3D Comment:
> >> pass # just a comment
> >> elif type(rec) =3D=3D ATComment:
> >> pass
> >> elif type(rec) =3D=3D Record:
> >> for pair in rec.fields:
> >> field, value =3D pair
> >> field =3D field.strip().lower()
> >> if type(value) =3D=3D Join:
> >> for part in value:
> >> if type(part) =3D=3D Block:
> >> if field not in fields:
> >> print p("Unknown field: %s" % field)
> >> continue
> >> if field =3D=3D "author" or field =3D=3D =
"editor":
> >> # FIX: break value into names
> >> else: # other than author
> >> data.append((field, part.flat()))
> >> else: # other than block
> >> data.append((field, part.flat()))
> >> else: # other than join
> >> data.append((field, value.flat()))
> >> else:
> >> print p("Unknown record type: %s" % type(rec))
> >> # do something with data
> >> # return something
> >
> > --
> > Fr=E9d=E9ric
> >
>
>
>
> -------------------------------------------------------------------------
> This SF.net email is sponsored by DB2 Express
> Download DB2 Express C - the FREE version of DB2 express and take
> control of your XML. No limits. Just data. Click to get it now.
> http://sourceforge.net/powerbar/db2/
> _______________________________________________
> Pybliographer-general mailing list
> Pybliographer-general-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
> https://lists.sourceforge.net/lists/listinfo/pybliographer-general
>
>
-- =
Fr=E9d=E9ric
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/