
    4YshO                     h    d Z ddlZddlmZmZ ddlmZ ddlmZm	Z	m
Z
mZ ddlZdgZ G d de      Zy)z
This is a rdflib plugin for parsing Hextuple files, which are Newline-Delimited JSON
(ndjson) files, into Conjunctive. The store that backs the graph *must* be able to
handle contexts, i.e. multiple graphs.
    N)ListUnion)Parser)ConjunctiveGraphURIRefLiteralBNodeHextuplesParserc                   H    e Zd ZdZd ZdefdZdedee	edf      fdZ
d	 Zy)
r
   z)
    An RDFLib parser for Hextuples

    c                      y )N )selfs    {/var/www/sten-cake5-migrate2.hellocrow.space/lexinfo-master/env/lib/python3.12/site-packages/rdflib/plugins/parsers/hext.py__init__zHextuplesParser.__init__   s        linec                 `    t        j                  |      D cg c]  }|dk7  r|nd  c}S c c}w )N )jsonloads)r   r   xs      r   _load_json_linezHextuplesParser._load_json_line   s*    04

40@A1Q"W$&AAAs   +cgtupNc                 D   |d   |d   
|d   |d   t        d      |d   j                  d      r t        |d   j                  dd      	      }nt	        |d         }t	        |d         }|d   d
k(  rt	        |d         }n]|d   dk(  r t        |d   j                  dd      	      }n5|d   t        |d   t	        |d               }nt        |d   |d         }|d   $t	        |d         }|j                  ||||f       y |j                  |||f       y )Nr            z2subject, predicate, value, datatype cannot be None_z_:r   )valueglobalIdlocalId   )datatype)lang   )
ValueError
startswithr	   replacer   r   add)r   r   r   spocs          r   _parse_hextuplezHextuplesParser._parse_hextuple   s.    q6>SV^s1v~QQRR q6S!CFNN445As1vA 3q6N q6Zs1vAVy CFNN445A1v~CFVCF^<CFQ0 q6s1vAFFAq!Q< FFAq!9r   c                    |j                  d      dvr(t        j                  d|j                  d       d       |j                  j                  sJ d       t        |j                  |j                        }||_        t        |d      rRt        |j                  j                        5 }|D ]#  }| j                  || j                  |             % 	 d d d        y t        |d      rpt        |j                  d	      rY|j                  j                  j!                         j#                         D ]#  }| j                  || j                  |             % y y y # 1 sw Y   y xY w)
Nencoding)Nzutf-8z8Hextuples files are always utf-8 encoded, I was passed: z", but I'm still going to use utf-8z-Hextuples Parser needs a context-aware store!)store
identifierfile_InputSource__bytefilewrapped)getwarningswarnr2   context_awarer   r3   default_contexthasattropenr4   namer/   r   r5   r6   strip
splitlines)r   sourcegraphkwargsr   fpls          r   parsezHextuplesParser.parseA   sY   ::j!8MM!!'J!7 8 933 KK%%	;:	;% EKKE<L<LM" 66"fkk&&' F2 FA((T-A-A!-DEFF F V56v44i@66>>DDFQQS FA((T-A-A!-DEF A 7F Fs   ,)EE%)__name__
__module____qualname____doc__r   strr   r   r   r   r/   rF   r   r   r   r
   r
      sC    
BC B""2 "eCI>N9O "HFr   )rJ   r   typingr   r   rdflib.parserr   rdflibr   r   r   r	   r8   __all__r
   r   r   r   <module>rP      s8   
     ; ;  
GFf GFr   