Help us understand the problem. What is going on with this article?

dbpediaの研究 その25

More than 1 year has passed since last update.

概要

dbpediaが難解なので、手出してみる。
javaで、取得してみた。

サンプルコード

import java.util.*;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLEncoder;

public class Main {
     public static String sendGet(String url, String param) {
        String result = "";
        BufferedReader in = null;
        try 
        {
            String urlNameString = url + "?" + param;
            URL realUrl = new URL(urlNameString);
            URLConnection connection = realUrl.openConnection();
            connection.setRequestProperty("accept", "*/*");
            connection.setRequestProperty("connection", "Keep-Alive");
            connection.setRequestProperty("user-agent", "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36");
            connection.connect();
            Map<String, List<String>> map = connection.getHeaderFields();
            for (String key : map.keySet()) 
            {
                System.out.println(key + "--->" + map.get(key));
            }
            in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
            String line;
            while ((line = in.readLine()) != null) 
            {
                result += line;
            }
        } 
        catch (Exception e) 
        {
            System.out.println("err!" + e);
            e.printStackTrace();
        }
        finally 
        {
            try
            {
                if (in != null)
                {
                    in.close();
                }
            }
            catch (Exception e2)
            {
                e2.printStackTrace();
            }
        }
        return result;
    }
    public static void main(String[] args) throws Exception {
        Main httpTest = new Main();
        String query = "query=" + URLEncoder.encode("SELECT DISTINCT * WHERE { dbpedia-ja:デ・トマソ dbpedia-owl:abstract ?abstract .}", "UTF-8");
        System.out.println(httpTest.sendGet("http://ja.dbpedia.org/sparql", query));
    }
}




成果物

https://paiza.io/projects/f2-WNirCplt9PQAH3XeK4g

以上。

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away