Annotation of libwww/Library/src/HTRDF.html, revision 2.9

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

Webmaster