0

I'm installing Hybrid Ranking algorithm for Linked Data Extraction & Context on Android. Documents you can search Google for the keywords above. And now I'm installing semantic similarity between two uri1 and uri2.

Input: two DBpedia URIs

Output: a value representing their similarity

private float similarity(String uri1, String uri2) {
     float wikipedia = wikiS(uri1, uri2);
     float abtract = abtractS(uri1, uri2);
     float google = engineS(uri1, uri2, google);
     float yahoo = engineS(uri1, uri2, yahoo);
     float bing = engineS(uri1, uri2, bing);
     float dilicious = engineS(uri1, uri2, dilicicous);
     return wikipedia + abtract + google + yahoo + bing + dilicious;
}

And with each child function, I have to query data using SPARQL dbpedia, google, yahoo, bing, dilicious using provided API. The results obtained will be calculated to the parser and returns the corresponding float value.

Example for abtractS(uri1, uri2) below:

private float abstractS(String uri1, String uri2, final float wikiS){
    String url = createUrlAbstractS(uri1, uri2);
    StringRequest request = new StringRequest(Request.Method.GET, url, new Response.Listener<String>() {
        @Override
        public void onResponse(String response) {
            float abtractS = 0.0f;
            try {
                JSONObject jsonObject = new JSONObject(response);
                JSONArray data = jsonObject.getJSONObject("results").getJSONArray("bindings");
                if(data.length() == 0){
                    showLogAndToast("No result");
                }else{
                    JSONObject element = data.getJSONObject(0);
                    String label1 = element.getJSONObject("label1").getString("value");
                    String abtract1 = element.getJSONObject("abtract1").getString("value");
                    String label2 = element.getJSONObject("label2").getString("value");
                    String abtract2 = element.getJSONObject("abtract2").getString("value");
                    abtractS = calWordContained(label1, abtract2) + calWordContained(label2, abtract1) + wikiS;
                    //TODO: RESULT ABTRACTS HERE. How next?
                }
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
    }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            Log.d(TAG, error.getMessage());
        }
    });
    AppController.getInstance().addToRequestQueue(request);
    return 0.0f;//HERE: no results
}

private float calWordContained(String label, String abtract){
    if(label.length() == 0 || abtract.length() == 0){
        return 0.0f;
    }
    List<String> words = Arrays.asList(label.split(" "));
    int count = 0;
    float length = words.size();
    for(int i = 0; i < length; i++){
        if(abtract.toLowerCase().contains(words.get(i).toLowerCase())){
            count++;
        }
    }
    return (count/length);
}

public String createUrlAbstractS(String uri1, String uri2){
    private String BASE_URL_DBPEDIA = "http://dbpedia.org/sparql?default-graph-uri=&query=";
    String query = createQueryAbstractS(uri1, uri2);
    String url = "";
    try {
        url = Config.BASE_URL_DBPEDIA + URLEncoder.encode(query, "UTF-8") + Config.RESULT_JSON_TYPE;
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }
    return url;
}

private String createQueryAbstractS(String uri1, String uri2){
    String query = Config.PREFIX_DBPEDIA + " \n" +
            "prefix dbpedia-owl: <http://dbpedia.org/ontology/>\n" +
            "\n" +
            "\n" +
            "select ?label1, ?label2, ?abtract1, ?abtract2 where\n" +
            "{\n" +
            "  {\n" +
            "     select *\n" +
            "     where{\n" +
            "          <" + uri1 + "> rdfs:label ?label1 ;\n" +
            "                         dbpedia-owl:abstract ?abtract1 .\n" +
            "          FILTER langMatches(lang(?abtract1),'en') . \n" +
            "          FILTER langMatches(lang(?label1),'en') .\n" +
            "     }\n" +
            "  }\n" +
            "\n" +
            "\n" +
            "  {\n" +
            "      select *\n" +
            "      where{\n" +
            "          <" + uri2 + "> rdfs:label ?label2 ;\n" +
            "                         dbpedia-owl:abstract ?abtract2 .\n" +
            "          FILTER langMatches(lang(?label2),'en') . \n" +
            "          FILTER langMatches(lang(?abtract2),'en') .\n" +
            "      }\n" +
            "  }\n" +
            "}";
    return query;
}

but how to do this on, I could not get the results I wanted in the similarity function (uri1, uri2). Therefore it will affect the results in different functions.

So I'm asking is: how can I get all the results of the function Wikis, abtractS, engine (google), engine (bing), engine (yahoo), engine (dilicious) in a simple way Best. I currently do on Android and data load times is very important.

Thank you very much!

Pham Hai
  • 55
  • 5
  • What do you mean by "how can I get all the results of the function Wikis, ..." ? You have to send a query to each search API, what else should be possible? – UninformedUser Jan 01 '17 at 14:09
  • By the way, for me it's not clear how meaningful a Google, Yahoo, etc. search for two DBpedia URIs can be...this sounds odd and more appropriate to use the label of both DBpedia resources instead. – UninformedUser Jan 01 '17 at 14:11
  • I want to get the data of Wikis, abtractS, engine (google) .. the similarity function to process later. But I have to send a query to retrieve data over the network, so the result of Wikis, abtractS, engine (google) .. can not take direct style: float wikis = Wikis (uri1, uri2) that I have to parse data in onResponse (String response) of it to get results. Therefore, I can not get results in the function similiraty (uri1, uri2). – Pham Hai Jan 01 '17 at 14:37
  • From what I understand, you need the result of all the volley requests to find similarity. Problem you are facing is that there is no mechanism to return volley response (abstractS in this case). To solve this, you can use [Interfaces](http://stackoverflow.com/questions/28120029/how-can-i-return-value-from-function-onresponse-of-volley) . Just go through this and see if you can figure it out. If not I'll help you. Try once. – Kartik Sharma Jan 01 '17 at 16:05
  • For me, the whole question is remains unclear, sorry to say that. It would be better to explain what **exactly** does **not** work. 1.) Fix the typos, e.g. `abtract` 2.) Can you send the queries for each of the search engine APIs and do you get a result back? 3.) Your SPARQL query looks strange. I don't understand why you use two sub-SELECTs. And have you tried the query in the DBpedia web-interface? Does it return the expected results? – UninformedUser Jan 01 '17 at 19:49
  • 4.) Again, it's really hard to read your question since there are obvious typos, e.g. method name `abtractS(uri1, uri2)` and the first code snippet and then a totally different method signature in the second part: `abstractS(String uri1, String uri2, final float wikiS)` – UninformedUser Jan 01 '17 at 19:49
  • @KartikSharma Thank you. I was thinking of using the Interface of my problem, but that it rather troublesome. Because the result of the similarity function (uri1, uri2) I can use in many places, and there is both recursive function again. – Pham Hai Jan 02 '17 at 08:49
  • @KartikSharma You can look at the link below algorithm. http://sisinflab.poliba.it/semantic-expert-finding/papers/tech-report-2-2012.pdf – Pham Hai Jan 02 '17 at 08:51
  • @AKSW 1.In abtractS function (uri1, uri2) I'm want to try in the following way: private void wikiS(uri1, uri2){ ... onResponse(String response){ wikiS = parseWikiS(response); abtractS(uri1, uri2, wikiS); } } private void abtractS(uri1, uri2, float wikiS){ .. onResponse(String response){ abtractS = parseAbtractS(response); engine(uri1, uri2, google, wikiS, abtractS); } } So, next for: engine(uri1, uri2, bing, wikiS, abtractS, googleS); – Pham Hai Jan 02 '17 at 08:59
  • 1. I want to try in the following way: wikiS(uri1, uri2) will call abtractS(uri1, uri2, float wikiS) will call engineS(uri1, uri2, google, wikiS, abtractS) will call...engineS(uri1, uri2, dilicious, wikiS, abtractS, googleS, bingS, yahooS) – Pham Hai Jan 02 '17 at 09:10
  • 2. I want to send the query to the search engine and get the results in a single place, it feasible? – Pham Hai Jan 02 '17 at 09:12
  • 3. The purpose query that I want to get label1, abtract1 of uri1 and LABEL2, abtract2 of uri2. – Pham Hai Jan 02 '17 at 09:13
  • 3. I query the web interface, the results returned json and I have to parse response to get uri. – Pham Hai Jan 02 '17 at 09:15
  • All your answers don't make it clearer. See your first code snippet. For instance line `float google = engineS(uri1, uri2, google);` -> why do you want to give the value `google` to the method? It should be clear that this doesn't work. – UninformedUser Jan 02 '17 at 11:45
  • And why do you have to pass the value of the previously computed similarity function to the next function? Why? Why can't you simply compute a similarity value for each search engine, and afterwards combine those measures? – UninformedUser Jan 02 '17 at 11:47
  • Ok, I think I understood the problem now. (Next time it would be good to mention that your API uses asynchronous HTTP requests.) In that case I'd suggest to read about asynchronous event handling first. And then you can try to use https://developer.android.com/reference/org/apache/http/protocol/HttpRequestExecutor.html which allows for synchronous HTTP request. Note, that with this method the request are not send in parallel but sequentially. – UninformedUser Jan 02 '17 at 11:57
  • Thank you very much. I will try to use the link you've recommended. Alternatively, you can evaluate my SPARQL statements are not okay? I still get a result: label1, and LABEL2 abtract1 of uri1, abtract2 of uri2, but as you say it seems difficult to understand, right? – Pham Hai Jan 02 '17 at 16:04

0 Answers0