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