study of dbpedia part 25

Overview

Since dbpedia is esoteric, I'll try it. I tried to get it with java.

Sample code

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:De Tomaso dbpedia-owl:abstract ?abstract .}", "UTF-8");
        System.out.println(httpTest.sendGet("http://ja.dbpedia.org/sparql", query));
    }
}




Deliverables

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

that's all.

Recommended Posts

study of dbpedia part 25
Introduction of Docker --Part 1--
Form part attributes of form_with
[Memo] JSUG Study Group 2019 Part 7 Utilization of Spring in Visional
Qualify only part of the text
Summary of [Java silver study] package
Basic usage of java Optional Part 1
Swift Network.framework Study 2019 1207 "Server TCP" Part 3 Use of receive method Improvement
Summary of in-house newcomer study session [Java]
part of the syntax of ruby ​​on rails
[In-house study session] Introduction of "Readable Code"
Spring Framework study notes [Part 1] DI container
Extract a part of a string with Ruby