Exemplo n.º 1
0
def ext_json():
    rdfUrl = ''
    tok = Tokenizer()
    if request.method == 'POST':
        rdf = request.form['data']
        status_test = "0"#request.form['status']
        filters = ""#request.form['exculdeurls']
        #rdf = "http://jpp.no-ip.org/MAD_J.rdf"
        try:
            #r = requests.get(rdf)
            gg = Graph()
            #g.load(rdfUrl)
            rdf_content = StringIO.StringIO(rdf.encode('utf-8'))
            #print rdf_content.readline()
            gg.parse(rdf_content,  format="xml")
            ext = Extractor(gg)
            uris = ext.getUris()
            mapping = MapFactory()
            for uri in uris:
                term = tok.tokenized_url(uri)
                uri_status = ""
                if status_test == "1":
                    uri_status = ext.testUri(uri)
                else:
                    uri_status = "N/A"  
                uri_lookup = str(uri)+"\"" 
                lnum = ext.get_lines(rdf_content, uri_lookup)          
                ent = MapEntry(uri, term, "", lnum, uri_status)
                mapping.add(ent)
            jsonized_result = json.dumps(mapping.get())              
            return Response(jsonized_result, mimetype='application/json')
        except requests.exceptions.ConnectionError:
            X2Rwarning = 'X2R Warning: The requested URL raises ConnectionError~!!!'
            return X2Rwarning
Exemplo n.º 2
0
def test():
    g = Graph()
    #g.parse("MAD_D.rdf", format="xml")
    f = open("./testsuite/test_fixtures/MAD_D.rdf", 'rb')
    st = f.read().decode('utf-8')
    print type(st)
    g.parse(StringIO.StringIO(st.encode('utf-8')),  format="xml")
    ext = Extractor(g)
    uris = ext.getUris()
    print ext.terms()
    ext.getBnodes()
Exemplo n.º 3
0
def ext_result():
    rdfUrl = ''
    if request.method == 'POST':
        rdfUrl = request.form['url']
        try:
            r = requests.get(rdfUrl)
            #rdfUrl = str(r.status_code)
            g = Graph()
            #g.parse("MAD.rdf", format="xml")
            g.load(rdfUrl)
            ext = Extractor(g)
            uris = ext.getUris()
            terms = ext.terms()
            result = {}
            result['uris'] = uris
            result['terms'] = terms
            result['bNodes'] =str(len(ext.getBnodes()))
            result['uNodes'] = str(len(uris))
            return render_template('index.html', result= result)
        except requests.exceptions.ConnectionError:
            X2Rwarning = 'X2R Warning: The requested URL raises ConnectionError~!!!'
            return X2Rwarning