 """<STR_LIT>""" <EOL> import microdata <EOL> from rdflib import URIRef , Literal , BNode , Namespace , RDF <EOL> from rdflib . plugin import register <EOL> from rdflib . parser import Parser <EOL> register ( "<STR_LIT>" , Parser , "<STR_LIT>" , "<STR_LIT>" ) <EOL> class MicrodataParser ( Parser ) : <EOL> def parse ( self , source , sink , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> for item in microdata . get_items ( source . getByteStream ( ) ) : <EOL> self . _add_item ( item , sink ) <EOL> def _add_item ( self , item , sink ) : <EOL> if item . itemid : 
 s = URIRef ( item . itemid . string ) 
 """<STR_LIT>""" <EOL> import microdata <EOL> from rdflib import URIRef , Literal , BNode , Namespace , RDF <EOL> from rdflib . plugin import register <EOL> from rdflib . parser import Parser <EOL> register ( "<STR_LIT>" , Parser , "<STR_LIT>" , "<STR_LIT>" ) <EOL> class MicrodataParser ( Parser ) : <EOL> def parse ( self , source , sink , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> for item in microdata . get_items ( source . getByteStream ( ) ) : <EOL> self . _add_item ( item , sink ) <EOL> def _add_item ( self , item , sink ) : <EOL> if item . itemid : <EOL> s = URIRef ( item . itemid . string ) <EOL> else : <EOL> s = BNode ( ) <EOL> if not item . itemtype : <EOL> return <EOL> ns = str ( item . itemtype ) <EOL> if ns . endswith ( "<STR_LIT:#>" ) or ns . endswith ( "<STR_LIT:/>" ) : <EOL> ns = Namespace ( item . itemtype ) <EOL> else : <EOL> ns = Namespace ( ns + "<STR_LIT:#>" ) <EOL> sink . add ( ( s , RDF . type , URIRef ( item . itemtype ) ) ) <EOL> for item_property , item_values in item . props . items ( ) : <EOL> p = ns [ item_property ] <EOL> for v in item_values : <EOL> if isinstance ( v , microdata . Item ) : <EOL> o = self . _add_item ( v , sink ) <EOL> elif isinstance ( v , microdata . URI ) : <EOL> o = URIRef ( str ( v ) ) <EOL> else : <EOL> o = Literal ( v ) <EOL> sink . add ( ( s , p , o ) ) <EOL> return s </s>
