Annotation of libwww/Library/src/HTRDF.html, revision 2.1
2.1 ! frystyk 1: <HTML>
! 2: <HEAD>
! 3: <TITLE>W3C Sample Code Library libwww RDF Parser</TITLE>
! 4: </HEAD>
! 5: <BODY>
! 6: <H1>
! 7: RDF Parser Based on Expat and SiRPAC
! 8: </H1>
! 9: <P>
! 10: <STRONG>Written and integrated into libwww by John Punin - thanks!</STRONG>
! 11: <P>
! 12: This module is implemented by <A HREF="HTRDF.c">HTRDF.c</A>, and is a part
! 13: of the <A HREF="http://www.w3.org/Library/"> W3C Sample Code Library</A>.
! 14: <P>
! 15: This RDF parser is based on Janne Saarela's Java based
! 16: <A href="/RDF/Implementations/SiRPAC/">SiRPAC</A> and
! 17: <A href="http://www.jclark.com/xml/expat.html">James Clark's expat XML
! 18: parser</A> which isincluded in the libwww CVS code base where I compile is
! 19: as two libraries: <CODE>libxmltok.a</CODE> and <CODE>libxmlparse.a</CODE>.
! 20: See the <A HREF="../External/">external modules that libwww works</A> with
! 21: for details.
! 22: <PRE>
! 23: #ifndef HTRDF_H
! 24: #define HTRDF_H
! 25:
! 26: #include "<A href="HTHash.html">HTHash.h</A>"
! 27:
! 28: #define RDFMS "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
! 29: #define RDFSCHEMA "http://www.w3.org/TR/WD-rdf-schema#"
! 30: #define XMLSCHEMA "xml"
! 31:
! 32: typedef char * String;
! 33: </PRE>
! 34: <H2>
! 35: <A NAME="HTTriple">RDF Triple Class</A>
! 36: </H2>
! 37: <PRE>
! 38: typedef struct _HTTriple HTTriple;
! 39:
! 40: extern HTTriple * HTTriple_new (String p, String s, String o);
! 41: extern BOOL HTTriple_delete (HTTriple * me);
! 42: extern void HTTriple_print (HTTriple * me);
! 43: extern String HTTriple_subject (HTTriple * me);
! 44: extern String HTTriple_predicate (HTTriple * me);
! 45: extern String HTTriple_object (HTTriple * me);
! 46: </PRE>
! 47: <H2>
! 48: <A NAME="HTElement">RDF Element Class</A>
! 49: </H2>
! 50: <PRE>
! 51: typedef struct _HTElement HTElement;
! 52:
! 53: extern HTElement * HTElement_new (String sName, HTAssocList * al);
! 54: extern HTElement * HTElement_new2 (String sContent);
! 55: extern BOOL HTElement_addData (HTElement *me, String sContent);
! 56: extern BOOL HTElement_delete (HTElement * me);
! 57: extern BOOL HTElement_addChild (HTElement * me, HTElement * element);
! 58: extern BOOL HTElement_addAttribute (HTElement * me, String sName, String sValue);
! 59: extern BOOL HTElement_removeAttribute (HTElement * me, String sName);
! 60: extern String HTElement_getAttribute (HTElement * me, String sName);
! 61: extern String HTElement_getAttribute2 (HTElement * me, String sNamespace, String sName);
! 62: extern BOOL HTElement_addTarget (HTElement * me, HTElement * element);
! 63: extern HTElement * HTElement_target (HTElement * me);
! 64: extern BOOL HTElement_instanceOfData (HTElement * me);
! 65: </PRE>
! 66: <H2>
! 67: <A NAME="HTRDF">RDF Parser & Compiler Definition</A>
! 68: </H2>
! 69: <P>
! 70: These methods create and deletes an RDF Parser/Compiler (SIRPAC)
! 71: <H3>
! 72: Create and Delete Parser Instance
! 73: </H3>
! 74: <PRE>
! 75: typedef struct _HTRDFParser HTRDF;
! 76:
! 77: extern HTRDF * HTRDF_new (void);
! 78: extern BOOL HTRDF_delete (HTRDF * me);
! 79: </PRE>
! 80: <H3>
! 81: <A NAME="newparser">Callback Handler Announcing a new RDF Parser Object</A>
! 82: </H3>
! 83: <P>
! 84: When a <A HREF="#converter">RDF parser object</A> is created, the stream
! 85: checks to see if there are any callbacks registered which should be notified
! 86: about the new stream instance. If that is the case then this callback is
! 87: called and a pointer to the RDF parser passed along. The output stream is
! 88: the target that was originally set for the request object before the request
! 89: was issued.
! 90: <PRE>
! 91: typedef void HTRDFCallback_new (
! 92: HTStream * me,
! 93: HTRequest * request,
! 94: HTFormat target_format,
! 95: HTStream * target_stream,
! 96: HTRDF * rdfparser,
! 97: void * context);
! 98: </PRE>
! 99: <H4>
! 100: Register RDF Parser Creation Notification Callback
! 101: </H4>
! 102: <P>
! 103: <STRONG>@@@Should be handled via XML names spaces@@@</STRONG>
! 104: <PRE>
! 105: extern BOOL HTRDF_registerNewParserCallback (HTRDFCallback_new *, void * context);
! 106: </PRE>
! 107: <H3>
! 108: <A NAME="newtriple">Callback Handler Announcing a new RDF Triple</A>
! 109: </H3>
! 110: <P>
! 111: Handler announcing that a new triple has been generated.
! 112: <PRE>
! 113: typedef void HTTripleCallback_new (
! 114: HTRDF * rdfp,
! 115: HTTriple * t,
! 116: void * context);
! 117: </PRE>
! 118: <H4>
! 119: Register RDF Triple Creation Notification Callback
! 120: </H4>
! 121: <PRE>
! 122: extern BOOL HTRDF_registerNewTripleCallback (
! 123: HTRDF * me,
! 124: HTTripleCallback_new * cbf,
! 125: void * context);
! 126: </PRE>
! 127: <H3>
! 128: Set Address
! 129: </H3>
! 130: <P>
! 131: Saves the name of the source document for later inspection if needed
! 132: <PRE>
! 133: extern BOOL HTRDF_setSource (HTRDF * me, String source);
! 134: </PRE>
! 135: <H3>
! 136: Resolve Symbolic References
! 137: </H3>
! 138: <P>
! 139: Go through the m_vResolveQueue and assign direct object reference for each
! 140: symbolic reference
! 141: <PRE>
! 142: extern BOOL HTRDF_resolve(HTRDF *me);
! 143: </PRE>
! 144: <H3>
! 145: Find Suitable Start Element
! 146: </H3>
! 147: <P>
! 148: Given an XML document (well-formed HTML, for example), look for a suitable
! 149: element to start parsing from
! 150: <PRE>
! 151: extern BOOL HTRDF_processXML(HTRDF *me, HTElement *root);
! 152: </PRE>
! 153: <H3>
! 154: Return the root element pointer.
! 155: </H3>
! 156: <P>
! 157: This requires the parsing has been already done.
! 158: <PRE>
! 159: extern HTElement * HTRDF_root(HTRDF *me);
! 160: </PRE>
! 161: <H3>
! 162: Return the full namespace URI for a given prefix sPrefix.
! 163: </H3>
! 164: <P>
! 165: The default namespace is identified with xmlns prefix. The namespace of xmlns
! 166: attribute is an empty string.
! 167: <PRE>
! 168: extern String HTRDF_namespace(HTRDF *me,String sPrefix);
! 169: </PRE>
! 170: <H3>
! 171: Parsing Literal or Resource?
! 172: </H3>
! 173: <P>
! 174: Methods to determine whether we are parsing parseType="Literal" or
! 175: parseType="Resource"
! 176: <PRE>
! 177: extern BOOL HTRDF_parseLiteral(HTRDF *me);
! 178: extern BOOL HTRDF_parseResource(HTRDF *me);
! 179: </PRE>
! 180: <H3>
! 181: Resolve Later
! 182: </H3>
! 183: <P>
! 184: Add the element e to the m_vResolveQueue to be resolved later.
! 185: <PRE>
! 186: extern void HTRDF_resolveLater(HTRDF *me,HTElement *e);
! 187: </PRE>
! 188: <H3>
! 189: Register ID
! 190: </H3>
! 191: <P>
! 192: Add an element e to the Hashtable m_hIDtable which stores all nodes with
! 193: an ID
! 194: <PRE>
! 195: extern void HTRDF_registerID(HTRDF *me,String sID,HTElement *e);
! 196: </PRE>
! 197: <H3>
! 198: Register Resource
! 199: </H3>
! 200: <P>
! 201: Add an element e to the Vector m_vResources which stores all nodes with an
! 202: URI
! 203: <PRE>
! 204: extern void HTRDF_registerResource(HTRDF *me,HTElement *e);
! 205: </PRE>
! 206: <H3>
! 207: Look for Node
! 208: </H3>
! 209: <P>
! 210: Look for a node by name sID from the Hashtable m_hIDtable of all registered
! 211: IDs.
! 212: <PRE>
! 213: extern HTElement *HTRDF_lookforNode(HTRDF *me,String sID);
! 214: </PRE>
! 215: <H3>
! 216: If Element from RDF Schema?
! 217: </H3>
! 218: <P>
! 219: Check if the element e is from the namespace of the RDF schema by comparing
! 220: only the beginning of the expanded element name with the canonical RDFMS
! 221: URI
! 222: <PRE>
! 223: extern BOOL HTRDF_isRDF(HTRDF *me, HTElement *ele);
! 224: extern BOOL HTRDF_isRDFroot(HTRDF *me, HTElement *ele);
! 225: </PRE>
! 226: <H3>
! 227: Is the element a Description?
! 228: </H3>
! 229: <PRE>
! 230: extern BOOL HTRDF_isDescription(HTRDF *me, HTElement *ele);
! 231: </PRE>
! 232: <H3>
! 233: Is the element a Predicate?
! 234: </H3>
! 235: <P>
! 236: This method matches all properties but those from RDF namespace
! 237: <PRE>
! 238: extern BOOL HTRDF_isTypedPredicate(HTRDF *me, HTElement *e);
! 239: </PRE>
! 240: <H3>
! 241: Is the element a Container?
! 242: </H3>
! 243: <PRE>
! 244: extern BOOL HTRDF_isContainer(HTRDF *me, HTElement *e);
! 245: </PRE>
! 246: <H3>
! 247: Is the element a Bag?
! 248: </H3>
! 249: <PRE>
! 250: extern BOOL HTRDF_isBag(HTRDF *me, HTElement *e);
! 251: </PRE>
! 252: <H3>
! 253: Is the element an Alternative?
! 254: </H3>
! 255: <PRE>
! 256: extern BOOL HTRDF_isAlternative(HTRDF *me, HTElement *e);
! 257: </PRE>
! 258: <H3>
! 259: Is the element a Sequence?
! 260: </H3>
! 261: <PRE>
! 262: extern BOOL HTRDF_isSequence(HTRDF *me, HTElement *e);
! 263: </PRE>
! 264: <H3>
! 265: Is the element a ListItem?
! 266: </H3>
! 267: <PRE>
! 268: extern BOOL HTRDF_isListItem (HTRDF *me, HTElement *e);
! 269: </PRE>
! 270: <H3>
! 271: Start processing an RDF/XML document instance from the root element rdf.
! 272: </H3>
! 273: <PRE>
! 274: extern BOOL HTRDF_processRDF(HTRDF *me, HTElement *ele);
! 275: </PRE>
! 276: <P>
! 277: processDescription manages Description elements
! 278: <DL COMPACT>
! 279: <DT>
! 280: description
! 281: <DD>
! 282: The Description element itself
! 283: <DT>
! 284: inPredicate
! 285: <DD>
! 286: Is this is a nested description
! 287: <DT>
! 288: reificate
! 289: <DD>
! 290: Do we need to reificate
! 291: <DT>
! 292: createBag
! 293: <DD>
! 294: Do we create a bag container
! 295: <DT>
! 296: return
! 297: <DD>
! 298: An ID for the description
! 299: </DL>
! 300: <PRE>
! 301: extern String HTRDF_processDescription (
! 302: HTRDF * me,
! 303: HTElement * description,
! 304: BOOL inPredicate,
! 305: BOOL reificate,
! 306: BOOL createBag);
! 307: </PRE>
! 308: <H3>
! 309: Manage the typedNode production in the RDF grammar.
! 310: </H3>
! 311: <PRE>
! 312: extern String HTRDF_processTypedNode(HTRDF *me, HTElement *e);
! 313: </PRE>
! 314: <H3>
! 315: Special method to deal with rdf:resource attribute
! 316: </H3>
! 317: <PRE>
! 318: extern String HTRDF_getResource(HTRDF *me,HTElement *e);
! 319: </PRE>
! 320: <H3>
! 321: Create a new reification ID
! 322: </H3>
! 323: <P>
! 324: Using a name part and an incremental counter m_iReificationCounter.
! 325: <PRE>
! 326: extern String HTRDF_newReificationID (HTRDF *me);
! 327: </PRE>
! 328: <H3>
! 329: Create a new triple
! 330: </H3>
! 331: <P>
! 332: and add it to the m_triples List
! 333: <PRE>
! 334: extern void HTRDF_addTriple (HTRDF *me, String sPredicate, String sSubject,
! 335: String sObject);
! 336: </PRE>
! 337: <H3>
! 338: Create New Bag
! 339: </H3>
! 340: <P>
! 341: allows one to determine whether SiRPAC produces Bag instances for each
! 342: Description block. The default setting is not to generate them.
! 343: <PRE>
! 344: extern void HTRDF_createBags (HTRDF *me, BOOL b);
! 345: </PRE>
! 346: <H3>
! 347: Set Output Stream
! 348: </H3>
! 349: <P>
! 350: Set output stream for RDF parser
! 351: <PRE>
! 352: extern void HTRDF_setOutputStream (HTRDF *me, HTStream *ostream);
! 353: </PRE>
! 354: <H2>
! 355: <A NAME="converter">RDF Converter Streams</A>
! 356: </H2>
! 357: <P>
! 358: A set of <A HREF="HTFormat.html">converter streams</A> using the
! 359: <A HREF="#HTRDF">HTRDF Parser object</A>
! 360: <H3>
! 361: RDF To Triple Converter
! 362: </H3>
! 363: <P>
! 364: This stream converter converts an RDF stream to triples that are passed to
! 365: the application using the <A HREF="#newtriple">new triples callback
! 366: handler</A>. The RDF object itself can be obtained using the
! 367: <A HREF="#newparser">new RDF parser object callback</A>
! 368: <PRE>
! 369: extern HTConverter HTRDFParser_new;
! 370: </PRE>
! 371: <H3>
! 372: Print RDF Triple Converter
! 373: </H3>
! 374: <P>
! 375: This stream converter converts an RDF stream to triples and sends them downstrem
! 376: as <TT>(predicate, subject, object)</TT>. This can for example be used to
! 377: print them out to stdout etc.
! 378: <PRE>
! 379: extern HTConverter HTRDFToTriples;
! 380: </PRE>
! 381: <PRE>
! 382: #endif
! 383: </PRE>
! 384: <P>
! 385: <HR>
! 386: <ADDRESS>
! 387: @(#) $Id: HTXML.html,v 2.2 1999/02/22 01:04:24 frystyk Exp $
! 388: </ADDRESS>
! 389: </BODY></HTML>
Webmaster