Exemplo n.º 1
0
      if ns.DATAFAQS['Satisfactory'] not in output.rdf_type:
         output.rdf_type.append(ns.DATAFAQS['Unsatisfactory'])

      output.save()

# Used when Twistd invokes this service b/c it is sitting in a deployed directory.
resource = W3CMailingListPerMonth()

# Used when this service is manually invoked from the command line (for testing).
if __name__ == '__main__':

   if len(sys.argv) == 0:
      print resource.name + ' running on port ' + str(resource.dev_port) + '. Invoke it with:'
      print 'curl -H "Content-Type: text/turtle" -d @my.ttl http://localhost:' + str(resource.dev_port) + '/' + resource.name
      sadi.publishTwistedService(resource, port=resource.dev_port)
   else:
      reader= open(sys.argv[1],"r")
      mimeType = "application/rdf+xml"
      if len(sys.argv) > 2:
         mimeType = sys.argv[2]
      if len(sys.argv) > 3:
         writer = open(sys.argv[3],"w")

      graph = resource.processGraph(reader,mimeType)

      if len(sys.argv) > 3:
         writer.write(resource.serialize(graph,mimeType))
      else:
         print resource.serialize(graph,mimeType)
Exemplo n.º 2
0
                  i = i + 1
                  if(i == len(each_pred) or i == len(each_other_pred)):
                      break
              i = 0
              
              if len(temp_ns) > 8: #meaningful
                  if len(temp_ns) < min_len:
                      possible_temp_ns = temp_ns
                      min_len = len(temp_ns)
              
          # find the highest index with / which indicate the end
          temp_ns = ""
          if(len(possible_temp_ns) > 0):
              tuple = possible_temp_ns.rpartition('/')
              temp_ns_list.append(tuple[0])
          possible_temp_ns = ""
          
      predicate_set = set(temp_ns_list)
      for row in predicate_set:
          print row
          output.datafaqs_namespaces.append("<" + row + ">")
                 
      output.save()

# Used when Twistd invokes this service b/c it is sitting in a deployed directory.
resource = vocabulary_count()

# Used when this service is manually invoked from the command line (for testing).
if __name__ == '__main__':
   sadi.publishTwistedService(resource, port=9110)
Exemplo n.º 3
0
Arquivo: get.py Projeto: leej35/lobi
            o=stmt[2]
            if type(stmt[2]) == URIRef:
                o = URIRef(absolutize(stmt[2],base))
            g.add((URIRef(absolutize(stmt[0],base)),
                    URIRef(absolutize(stmt[1],base)),
                    o))
        c = g.serialize(format='xml')
        graph.parse(StringIO(c), format='xml')
        
    def process(self, input, output):
        store = output.session.default_store
        headers = {'Accept':acceptHeader}
        request = Request(str(output.subject), None, headers)
        cnxn = urlopen(request)
        content = cnxn.read()
        #print content
        contentType = cnxn.headers['Content-Type']
        print contentType
        try:
            self.parse(store.reader.graph,content,contentType,cnxn.url)
        except:
            fe = urllib.splitquery(cnxn.url)[0].split('.')[-1]
            self.parse(store.reader.graph,content,extensions[fe],cnxn.url)

resource = Get()

# Set up the service to listen on port 9090
if __name__ == "__main__":
    sadi.publishTwistedService(resource, port=9090)