site_graphlogo
  -   Terms of Use and Privacy
Source Code
site_graphlogo
  -   Terms of Use and Privacy
Source Code

Source Code | Create Triples

This program generates triples from the IT Docent DFD.

#!/usr/bin/python3
#Create TRIPLES for import into graph db
#Copyright (C) 2020 Tributary Software

#This program is free software; you can redistribute it and/or
#modify it under the terms of the GNU General Public License
#as published by the Free Software Foundation; either version 2
#of the License, or (at your option) any later version.

#This program is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#GNU General Public License for more details.

#You should have received a copy of the GNU General Public License
#along with this program; if not, write to the Free Software
#Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
#or view the license here: https://tributarysoftware.com/gpl2.txt
import re
import os
#out='/home/knoppix/websites/site/itd/graph/'
out='/home/knoppix/websites/site/cod/graph/'
#rootd='/home/knoppix/websites/source/itd/0/'
rootd='/home/knoppix/websites/source/cod/0/4/32/2/'
triples=[]
padds=[]
for root,dirs,files in os.walk(rootd, followlinks=False):
   for fname in files:
      if not fname.startswith('.') and fname[-13:]!='predlabel.txt' and fname[-11:]!='details.txt' and fname.find('^^')==-1 and fname.find('_component_destination')==-1 and fname.find('_flow_destination')==-1:
         padds.clear()
         p=os.path.join(root,fname)
         #bits=re.compile('^.+/source/itd/0/(.+)/(has_specified_input|has_specified_output|has_specified_inp_and_out)/(.+)$')
         bits=re.compile('^.+/source/cod/0/4/32/2/(.+)/(has_specified_input|has_specified_output|has_specified_inp_and_out)/(.+)$')
         try:
            m = bits.match(p)
            subpath=m.group(1)
            bitsf=''
            ld=''
            for bit in subpath.split('/'):
               parent=bitsf
               if parent=='':
                  parent='0'
                  bitsf+=bit+'.'
               else:
                  bitsf+=bit+'.'
                  trpl='<http://purl.obolibrary.org/obo/OBI_0000011#0.'+bitsf[:-1]+'> <http://www.w3.org/2000/01/rdf-schema#subClassOf> <http://purl.obolibrary.org/obo/OBI_0000011#0.'+parent[:-1]+'>'
                  if trpl in triples:
                     six=9
                  else:
                     triples.append(trpl)
            subject=subpath.replace('/','.')
            if os.path.isfile(rootd+subpath+'.contains.txt'):
               with open(rootd+subpath+'.contains.txt') as f:
                  triples.append('<http://purl.obolibrary.org/obo/OBI_0000011#0.'+subject+'> <http://purl.obolibrary.org/obo/BFO_0000067> <http://purl.obolibrary.org/obo/OBI_0000011#'+f.read()+'>')
            predicate=m.group(2)
            objctraw=m.group(3)
            ttl=objctraw.find('title.txt')
            if ttl==-1:
               objct=objctraw[:-4]
               objctp=objctraw
            else:
               objct=objctraw[:ttl-1]
               objctp=objctraw
            if predicate=='has_specified_inp_and_out':
               padds=['<http://purl.obolibrary.org/obo/OBI_0000293>','<http://purl.obolibrary.org/obo/OBI_0000299>']
            elif predicate=='has_specified_output':
               padds=['<http://purl.obolibrary.org/obo/OBI_0000299>']
            elif predicate=='has_specified_input':
               padds=['<http://purl.obolibrary.org/obo/OBI_0000293>']
            ld=subject.rfind('.')
            if ld!=-1:
               level='0.'+subject[:ld]+'.'
            else:
               level='0.'
            mo=re.search('\d|\.',objct)
            if objct.find('D')!=-1 and mo:
               for padd in padds:
                  triples.append('<http://purl.obolibrary.org/obo/OBI_0000011#0.'+subject+'> '+padd+' <http://purl.obolibrary.org/obo/IAO_0000030#'+level+objct+'>')
            elif mo:
               for padd in padds:
                  triples.append('<http://purl.obolibrary.org/obo/OBI_0000011#0.'+subject+'> '+padd+' <http://purl.obolibrary.org/obo/OBI_0000011#'+objct+'>')
            if not(objct.find('D')!=-1 and mo) and not mo:
               for padd in padds:
                  triples.append('<http://purl.obolibrary.org/obo/OBI_0000011#0.'+subject+'> '+padd+' <http://purl.obolibrary.org/obo/BFO_0000023#'+level+objct+'>')
         except:
            six=9
for t in triples:
   print(t+' .')

raw source