Overview# ShEx is described on Wikipedia as:
Shape Expressions is a data modeling language for validating and describing Resource Description Framework
Here are my notes from attempting to create a ShEx file.
Creating a ShEx File# This time, we start with RDF data in data/tmp/merged.ttl. We use shexer to create a ShEx file from the RDF data.
p i p i n s t a l l s h e x e r
Get the list of classes in the RDF data.
f i g g k S W } q t f t r n r r n E H " r a o a o p a a o L E " e r r r m u p p w E R " s g g t h h s C E ? e r t e r _ . _ T a = t o a t d n = p q { _ w r _ f t a u D a g c g c l _ G r e I r l i e l i f r s r S ? a a n t a b i a e y T c p s _ s l p ( I l h s q c s i e h i = N s . e r l e m ( n C q s e a s p = ) p " T u s s o u " e = : s r " t " ? r e t d _ c y [ s a n l ( ] . G t t s k a r a _ n p a / f o p p t i w e h m l s n p e _ d / , q ( m u f e f e " r o r { g r y r e m ) o d a w . t . t = c t " l l t s " u } r " t ) l e " )
Process the retrieved classes.
f f s o s p r r h u h r o o a t a i m m p p p n e u e t s s r t r ( h h _ . " e e = f s D x x i h o e e S l e n r r h e x e . . a _ ! s c p = g " h o e r ) a n r " a p s ( d p e t t i g a h r s a n r t ( r p a a o a i i g u p / u c m m e t h t t c p p t _ _ m p e o o _ f f p u p r r c o i / t t t t l r l s _ a a m e h f n S N s a _ a i c h T s t i p l e a , e = n e e _ p s T p s = t e S = U u . o h r H t R t s u r E a T = h t e X r L i e p s C g E n x u h , e , p " t o t u _ l S _ t f d H c _ i = A l n l 0 C a t e . L s _ , 1 _ s f ) T e i U s l R , e T ) L E , T U R T L E
As a result, the following ShEx file was created.
: { 教 育 メ e r s e e r e e タ x d c x x d x x デ p f h p p f p p ー : : e : : s : : タ 指 t m 学 教 : 学 時 導 y a 年 科 l 習 代 要 p : a 指 領 e g b 導 コ e @ @ e 案 @ ー # o # # # # : # # # # # : # # # # # l : # # # # # # ド [ 学 教 時 1 d 2 1 1 1 年 2 1 1 1 1 科 1 1 1 1 1 I 代 9 2 1 1 1 1 2 a I 1 2 2 0 1 6 0 0 0 8 5 2 2 0 x R 6 3 5 5 3 2 I . t R . . . . . . . . . . . . . . s I . . . . . . R 3 a I 5 3 3 7 + 5 9 7 7 7 + 4 3 3 3 7 d * 9 0 3 3 8 3 I 0 : 3 0 0 6 ; 3 2 6 6 6 ; 6 8 0 0 6 : ; 2 7 8 8 4 0 7 教 8 7 7 9 8 3 9 9 9 1 4 7 7 9 s ; 3 6 4 4 6 7 6 育 + 4 6 6 2 4 0 2 2 2 5 6 6 6 2 t 0 9 6 6 1 6 + 9 メ ; 6 9 9 3 6 7 3 3 3 3 1 9 9 3 r 7 2 1 1 5 9 ; 2 タ 1 2 2 0 1 6 0 0 0 8 5 2 2 0 i 6 3 5 5 3 2 3 デ 5 3 3 7 5 9 7 7 7 4 3 3 3 7 n 9 0 3 3 8 3 0 ー 3 0 0 6 3 2 6 6 6 6 8 0 0 6 g 2 7 8 8 4 0 7 タ 8 7 7 9 8 3 9 9 9 1 4 7 7 9 3 6 4 4 6 7 6 ] 4 6 6 2 4 0 2 2 2 5 6 6 6 2 0 9 6 6 1 6 9 6 9 9 3 6 7 3 3 3 3 1 9 9 3 ; 7 2 1 1 5 9 2 1 2 2 0 1 6 0 0 0 8 5 2 2 0 6 3 5 5 3 2 3 ; 5 3 3 7 5 9 7 7 7 4 3 3 3 7 9 0 3 3 8 3 0 4 0 0 7 4 2 7 7 7 6 8 0 0 7 2 7 8 8 4 0 8 8 8 3 3 5 8 8 7 5 5 7 8 % % % % % % % % % % % % % % % % % % % % % o o o o o o o o o b o o b b o b b b o o o o b b o o o o o b j b b j j b j j j b b b b j j b b b b b j : j j : : j : : : j j j j : : j j j j j : : : : : : : : : : : : : I I @ @ @ @ @ @ I R I I R : @ : : : @ @ @ @ : : @ @ @ @ @ R I R R I 学 : 学 学 学 : : : : 教 時 : : : : : I . I I . 年 学 年 年 年 教 教 教 教 科 代 時 時 時 時 時 . . . . 年 . . . 科 科 科 科 . . 代 代 代 代 代 C C . . . . . . . . . . C a C C a C C C C C C a r a a r a C a a a C C C C a a C C C C C r d r r d r a r r r a a a a r r a a a a a d i d d i d r d d d r r r r d d r r r r r i n i i n i d i i i d d d d i i d d d d d n a n n a n i n n n i i i i n n i i i i i a l a a l a n a a a n n n n a a n n n n n l i l l i l a l l l a a a a l l a a a a a i t i i t i l i i i l l l l i i l l l l l t y t t y t i t t t i i i i t t i i i i i y : y y : y t y y y t t t t y y t t t t t : : : : y : : : y y y y : : y y y y y { { : : : : : : : : : : { 1 { { 2 { { { { { + 7 } 3 6 } 5 { 6 4 3 { { { { 5 { { { { { } } } } 1 } } } 8 3 6 4 } 2 1 3 4 6 } } } } } } } } } } # # # # # # # 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 . . . . . . . 0 0 0 0 0 0 0 % % % % % % %
Here, we convert the ShEx file created above to Turtle format.
Converting ShEx to ShExJ# There may be other methods, but here we use Node.js to convert to JSON format.
n p m i n s t a l l s h e x
/ n o d e _ m o d u l e s / @ s h e x j s / c l i / b i n / s h e x - t o - j s o n d a t a / t m p / s h a p e s . s h e x > d a t a / t m p / s h a p e s . s h e x j
The following JSON file was generated.
{ " " t s y h { p a e p " " " " e i t s : s d y h " " " " p a t e " : : e p y x " " S " e p p t e c [ " : E e r y x { } { } h h x " e p p , , e t " p : s e r " " " } " " " } " " m t S r s " e t p v t p v , m m a p h " " i : s y r a " " ] y r a " " i a " : a : S o s p e l t v p e l t d n x , / p h n " i e d u y a " e d u y a " " / e { a " E o " i e p l h " i e p t : : w D p : a n : c E e u t : c E e a e e e c s a x " e t a x " t 1 - s c " { h " " t p : s p " t p : y , 1 o l , O : T e r " : T e r p . " f r " " " : / r " " " e e , " [ i : : N / i : : N " s , p o [ w p o : / l " { d w l " { d s e h e w e h e " h C t C . C t C h a o t o w o t o t p n p n 3 n p n t e s : s . s : s p s t / t o t / t : / r / r r r / r / C a w a g a w a / l i w i / i w i w a n w n 2 n w n w s t . t 0 t . t w s " w " 0 " w " . " , 3 , 0 , 3 , w , . / . 3 o 0 o . r 1 r o g / g r / r / g 1 d 2 / 9 f 0 1 9 - 0 9 9 s 0 9 / c / 9 0 h 0 / 2 e 1 0 / m / 2 2 a r / 2 # d 2 - C f 2 r l - - d a s r f s c d - s h f s " e - y m s n a y t # n a l t x a a - b x n e - s l n # " s t , # y l p a e n " g , S t r i n g "
Convert to Turtle using rdflib.
i f I O # w # s # g # g # t # w p m r N U i h . u i r p o P T L t P e C = L p S r S t i o m U P o h a x r o a e t a h n r T U a s r _ e G a r r l v f t t r _ T d o h s j a r d s i e e o i ( d P _ p e e t a e a _ p l " j f A P S e x = e p S ( l o t e e S s l T A h n _ S h h d i u h n . h o i H T E ( j h j a ( E a z t e ( w E n b H x I _ E s ) x t e p O r x = J N s x o n J a u T U i i = P t J n e = t t u T t s m " s U r . w s j h r P e c p d " c T s l c s e = t U ( h o a d h _ = c o R h o l T t e r t a e P h a D e n g g e _ u m t a t m A f e d F m . r . P r a / a a T i m s a d a s o A t G t / H l a ( g u p e u T l h r m t f , e s r i m h r t H e a a p m r . a h a n p i p , _ s p / p o " r s e p t s t a u o h s / m r e x h o ( o l t " u b h s " a J _ s i w t e a h a ) d S j t h T z t " p e p a ( O _ h e u e o ) u n e p f a ) N s e x r ( t s e i s t _ t f a a ) s . s l r g j l o s u s . e f ) r ) e r f c h t i a , m i f c e t l p f a l i e x l e h f o t e l s j " : o r = e s " r m " : f m a t u a t u l t r l = t y " l j e c s " o o ) n n v - e l r d t " e ) d t o T u r t l e . " )
As a result, the following Turtle file was created.
< h t t p s . : h . / e . / x w : e s s h o a . p s e e h s E e / x x s p : h r e a x p [ p e r s s a e h / s e 教 s s x 育 h i : メ e o e タ x n x デ : p ー S [ r タ h e > a a s p s a e s i s s s s s s s s s s s h o h h h h h h h h h h h < ; e n e e e e e e e e e e e f x s x x x x x x x x x x x i : : : : : : : : : : : : l E ( m m p v p v m m p v m e a a i r a r a a i r a a : c [ x n e l e l x n e l x / h d u s d u s d u s / O a - 1 i e h i e h - 1 i e h - / f 1 c E e c E e 1 c E e 1 U s ; a x x a x x ; a x x s ; h ; t p : t p : ; t p : ; e e e r n e r v e r n r x o a o s : < [ d r [ l < [ d / T h e d u h e n r t a K f a e t a K a i t i : s t i k p p s n t s p s n a l s h d y h ( : h d m e : e p e / e u C / x s e x < / x s r o / : h : h s : h a n w N e ; N t c N e / s 3 o x o t h o x g t i d : d p e d : i r d e i e s m e i t a . C r C : a C r / i o o i o / . o i o n r n n / o n i t g s ] s w r s ] / / t t 3 g t o ; s r ] r i / r ] i u a a d g a / k i [ i . e i [ d i n n o o n e l t a t r > t a m a g o m ; s ; / ; ; s / - h s h s e e u e r d x k x c u : i : / c T l T S a r a r h t i m i a i p - p p o l e l e n e d e D a C u C e l o c o c - n a n l m s t s > e t i t t r o r ; a a n a d i a i a n l n t t - t a m / ; e ; t t e a r d m a / t p a r / o d p a e t r a t / y 教 # 育 指 メ 導 タ 要 デ 領 ー コ タ ー > ド > ) ; ] ] [ a s h e x : T r i p l e C o n s t r a i n t ;
Summary# Due to my insufficient knowledge of ShEx, I have not been able to verify whether the output is correct, but I was at least able to generate ShEx-related files from my existing RDF data.
I plan to study ShEx further and refine this in the future.