diff --git a/conllusvg/conllusvgRtoL.js b/conllusvg/conllusvgRtoL.js new file mode 100644 index 0000000000000000000000000000000000000000..1ac64a3d229bef5454f96502532a6f3b88003a12 --- /dev/null +++ b/conllusvg/conllusvgRtoL.js @@ -0,0 +1,245 @@ +// CoNLL-U SVG RtoL by Koichi Yasuoka, September 19, 2020. +// "conllusvgview.js" is needed. +"use strict"; +conllusvg.writeNodesSVG=function(textid){ + var c=conllusvg.main[textid]; + var n,g,t,w; + c.svg.setAttribute("width",c.width); + c.svg.setAttribute("height",c.height); + c.svg.setAttribute("transform","scale(-1,1)"); + for(n in c.nodes){ + g=document.createElementNS("http://www.w3.org/2000/svg","g"); + g.setAttribute("stroke","black"); + g.setAttribute("fill","black"); + if(c.nodes[n].svg!=null) + c.svg.removeChild(c.nodes[n].svg); + c.nodes[n].svg=g; + c.svg.appendChild(g); + t=document.createElementNS("http://www.w3.org/2000/svg","text"); + t.textContent=(c.nodes[n].upostag=="_")?"???":c.nodes[n].upostag; + t.setAttribute("transform","scale(-1,1)"); + t.setAttribute("x",-c.nodes[n].x); + t.setAttribute("y",c.nodes[n].y+17); + t.setAttribute("text-anchor","middle"); + t.setAttribute("font-family","sans-serif"); + t.setAttribute("font-size",15); + t.setAttribute("stroke","none"); + g.appendChild(t); + w=t.getBBox().width; + t=document.createElementNS("http://www.w3.org/2000/svg","rect"); + t.setAttribute("x",c.nodes[n].x-w/2-5); + t.setAttribute("y",c.nodes[n].y+1); + t.setAttribute("width",w+10); + t.setAttribute("height",20); + t.setAttribute("rx",5); + t.setAttribute("ry",5); + t.setAttribute("stroke-width",2); + t.setAttribute("fill","none"); + g.appendChild(t); + if(c.nodes[n].xpostag!="_"){ + t=document.createElementNS("http://www.w3.org/2000/svg","text"); + t.textContent=c.nodes[n].xpostag; + t.setAttribute("transform","scale(-1,1)"); + t.setAttribute("x",-c.nodes[n].x); + t.setAttribute("y",c.nodes[n].y+30); + t.setAttribute("text-anchor","middle"); + t.setAttribute("font-family","sans-serif"); + t.setAttribute("font-size",8); + t.setAttribute("stroke","none"); + g.appendChild(t); + w=t.getBBox().width; + if(w>90){ + t.setAttribute("transform","scale("+(90/w)+",1)"); + t.setAttribute("x",c.nodes[n].x*w/90); + } + } + if(c.nodes[n].form!="_"){ + t=document.createElementNS("http://www.w3.org/2000/svg","text"); + t.textContent=c.nodes[n].form; + t.setAttribute("transform","scale(-1,1)"); + t.setAttribute("x",-c.nodes[n].x); + t.setAttribute("y",c.nodes[n].y+60); + t.setAttribute("text-anchor","middle"); + t.setAttribute("font-family","sans-serif"); + t.setAttribute("font-size",30); + t.setAttribute("stroke","none"); + if(c.nodes[n].misc.indexOf("FontStyle=Italic")>=0) + t.setAttribute("font-style","oblique"); + g.appendChild(t); + w=t.getBBox().width; + if(w>90){ + t.setAttribute("transform","scale("+(-90/w)+",1)"); + t.setAttribute("x",-c.nodes[n].x*w/90); + } + } + w=c.nodes[n].misc.match(/(Gloss|Translit)=[^|]+/); + if(w!=null){ + t=document.createElementNS("http://www.w3.org/2000/svg","text"); + t.textContent=w[0].slice(w[0].indexOf("=")+1); + t.setAttribute("transform","scale(-1,1)"); + t.setAttribute("x",-c.nodes[n].x); + t.setAttribute("y",c.nodes[n].y+75); + t.setAttribute("text-anchor","middle"); + t.setAttribute("font-family","serif"); + t.setAttribute("font-size",12); + t.setAttribute("stroke","none"); + g.appendChild(t); + w=t.getBBox().width; + if(w>90){ + t.setAttribute("transform","scale("+(-90/w)+",1)"); + t.setAttribute("x",-c.nodes[n].x*w/90); + } + } + } +} +conllusvg.writeLinksSVG=function(textid){ + var c=conllusvg.main[textid]; + var n,g; + c.svg.setAttribute("width",c.width); + c.svg.setAttribute("height",c.height); + c.svg.setAttribute("transform","scale(-1,1)") + for(n in c.links){ + g=document.createElementNS("http://www.w3.org/2000/svg","g"); + g.setAttribute("stroke","black"); + g.setAttribute("fill","black"); + if(c.links[n].svg!=null) + c.svg.removeChild(c.links[n].svg); + c.links[n].svg=g; + c.svg.appendChild(g); + if(c.links[n].type=="root") + conllusvg.writeLinksSVGroot(c.links[n]); + else if(c.links[n].type=="single") + conllusvg.writeLinksSVGsingle(c.links[n]); + else if(c.links[n].type=="double") + conllusvg.writeLinksSVGdouble(c.links[n]); + } +} +conllusvg.writeLinksSVGroot=function(link){ + var t,w; + t=document.createElementNS("http://www.w3.org/2000/svg","text"); + t.textContent=(link.deprel=="_")?"root":link.deprel; + t.setAttribute("transform","scale(-1,1)"); + t.setAttribute("x",-link.fromX); + t.setAttribute("y",link.fromY+5); + t.setAttribute("text-anchor","middle"); + t.setAttribute("font-family","sans-serif"); + t.setAttribute("font-size",15); + t.setAttribute("stroke","none"); + link.svg.appendChild(t); + w=t.getBBox().width; + if(w>90){ + t.setAttribute("transform","scale("+(-90/w)+",1)"); + t.setAttribute("x",-link.fromX*w/90); + } + t=document.createElementNS("http://www.w3.org/2000/svg","path"); + t.setAttribute("fill","none"); + t.setAttribute("stroke-width",1); + t.setAttribute("d","M "+link.fromX+" "+(link.fromY+5)+" v "+(link.toY-link.fromY-5)); + link.svg.appendChild(t); + t=document.createElementNS("http://www.w3.org/2000/svg","path"); + t.setAttribute("d","M "+link.toX+" "+link.toY+" l -4 -10 h 8 Z"); + link.svg.appendChild(t); +} +conllusvg.writeLinksSVGsingle=function(link){ + var j=(link.fromX + +CoNLL-U SVG Editor RtoL by Koichi Yasuoka, September 19, 2020. + + + + + + + +
+ + + +
+ + + +