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.

pipinstallshexer

Get the list of classes in the RDF data.

figgkSW}qtftrnrrnEH"raoaopaaoLE"errrmuppwER"sggthhsCE?erter_._Ta=toatdn=pq{_wr_ftauDagcgcl_GreIrlielifrsrS?aantabiaeyTcps_slp(Ilhsqcsiehi=Ns.erlem(nCqseasp=)p"Tussou"e=:sr"t"?retd_cy[sanl(].Gttskara_npa/fopptiwehmlsnpe_d/,q(mufefe"ror{gryrem)odaw.t.t=ct"llts"u}r"t)le")

Process the retrieved classes.

ffsosprrhuhrooataimmpppneuetssrtr(hh_."ee=fsDxxihoeeSlenrrhexe..a_!scp=g"hoer)anr"aps(dpettigahrsanrt(rpaaoaiigup/ucmmethttcppt__mpeoo_ffpuprrcoi/ttttlrls_aamehfnSNsa_aichTstiplea,e=nee_psTps=teS=Uu.ohrHtRtsurEaT=hteXrLiepsCgEnxuh,e,p"totu_lS_tfdHc_i=Alnl0Cate.Ls_,1_sf)TeiUslR,eT)LE,TURTLE

As a result, the following ShEx file was created.

:{erseereexdcxxdxxpfhppfpp::e::s::tm:yalp:aegbe@@e@#o####:#####:#####l:######[1d21112111111111I9211112aI12201600085220xR635532I.tR..............sI......R3aI5337+59777+43337d*903383I0:3006;32666;68006:;278840787798399914779s;3644676+46624022256662t096616+9;69936733331993r721159;212201600085220i635532353375977743337n903383030063266668006g2788407877983999147793644676]46624022256662096616969936733331993;7211592122016000852206355323;533759777433379033830400742777680072788408883358875578%%%%%%%%%%%%%%%%%%%%%oooooooooboobbobbboooobbooooobjbbjjbjjjbbbbjjbbbbbj:jj::j:::jjjj::jjjjj:::::::::::::II@@@@@@IRIIR:@:::@@@@::@@@@@RIRRI::::::::::I.II..........CC..........CaCCaCCCCCCaraaraCaaaCCCCaaCCCCCrdrrdrarrraaaarraaaaadiddidrdddrrrrddrrrrriniinidiiiddddiidddddnannaninnniiiinniiiiialaalanaaannnnaannnnnlillilalllaaaallaaaaaitiitiliiilllliillllltyttytitttiiiittiiiiiy:yy:ytyyyttttyyttttt::::y:::yyyy::yyyyy{{::::::::::{1{{2{{{{{+7}36}5{643{{{{5{{{{{}}}}1}}}8364}21346}}}}}}}}}}#######111111100000000000000.......0000000%%%%%%%

Converting ShEx to Turtle Format

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.

npminstallshex
/node_modules/@shexjs/cli/bin/shex-to-jsondata/tmp/shapes.shex>data/tmp/shapes.shexj

The following JSON file was generated.

{""tsyh{paep""""eits:sdyh""""pate"::epyx""S"epptec[":Eeryx{}{}hhx"epp,,et"p:ser"""}"""}""mtSrs"etpvtpv,mmaph""i:syra""]yra""ia":a:Sospeltvpeltdnx,/phn"ieduya"eduya""/e{a"Eo"ieplh"iept::wDp:an:cEeut:cEeaeeecsax"etax"t1-sc"{h""tp:sp"tp:y,1ol,O:Ter":Terp."fr""":/r"""ee,"[i::N/i::N"s,po[wpo:/l"{dwl"{dsehewehe"hCtC.CtChaotowototpnpn3npntes:s.s:spst/tot/t:/r/rrr/r/Cawagawa/liwi/iwiwanwn2nwnwst.t0t.tws"w"0"w".",3,0,3,w,./.3o0o.r1rog/gr/r/g1d2/9f019-099s09/c/90h0/2e10/m/22ar/2#d2-Cf2rl--dasrfscd-shfs"e-ymsnayt#naltxaa-bxne-sln#"st,#ylpaen"g,String"

Converting ShExJ to Turtle Format

Convert to Turtle using rdflib.

ifIO#w#s#g#g#t#wpmrNUih.uirpoPTLtPeC=LpSrStiomUPohaxroaetahnrTUasr_eGarrlvfttr_Tdohsjardsieeoi(dP_peetaea_pl"jfAPSex=epS(loteeSslTAhn_Shhdiuhn.hoiHTE(jhja(Eazte(wEnbHxI_Es)xtepOrx=JNsxonJauTUii=PtJne=ttuTtsm"sUr.wsjhrPecpd"cTslcse=tU(hoadh_=coRholTtertaePhaDengge_umtatmAfedFm.r.Pra/aaTimsadasoAtGt/Hla(gupeuTlhrmtf,esrimhrtHeaapmr.ahanpip,_sp/po"rseptstauohs/mrexho(olt"ubhs"aJ_siwteaha)dSjthTzt"pepa(O_heueo)unepfa)Nsexr(tseist_tfaa)s.slrgjlosus.ef)r)erfchtia,mifcetlpfaliexlehfotelsj":or=es"rm":fmatuatultrl=ty"ljecs"oo)nnv-elrdt"e)dtoTurtle.")

As a result, the following Turtle file was created.

<https.:h./e./xw:esshoa.pseehsEe/xxsp:hreaxp[perssaeh/sessxhi:eoexnx:pS[rhe>aaspsaesissssssssssshohhhhhhhhhhh<;eneeeeeeeeeeefxsxxxxxxxxxxxi::::::::::::lE(mmpvpvmmpvmeaairaraairaa:c[xnelelxnelx/hdusdusdus/Oa-1iehieh-1ieh-/f1cEecEe1cEe1Us;axxaxx;axxs;h;tp:tp:;tp:;eeernervernrxoaos:<[dr[l<[d/TheduhenrtaKfaetaKaiti:stikppsntspsnalshdyh(:hdme:epe/euC/xsex</xsro/:h:hs:hanwNe;NtcNe/s3oxothoxgtid:dped:irdeiesmeita.CrC:aCr/iooio/.oionrnn/onitgs]swrs]//tt3gto;sr]ri/r]iuaadga/ki[i.ei[dinnooneltatr>tamagom;s;/;;s/-hshseeuerdxkxcu:i:/cTlTSararhtimiaip-ppolelenedeDaCuCelococ-nanlmsts>etittror;aanadiaianlntt-tam/;e;tteardma/tpar/odpaetrat/y#>>);]][ashex:TripleConstraint;

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.