Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Anlamsal Web BIL-534 [Ödev 3] Dersi veren: Yrd. Doç. Murat Osman Ünalır Hazırlayan: Sinem GETİR [Bahar 2010] [“Ontoloji arama motorlarından Swoogle ve Watson ın incelenmesi&uygulanması.] Swoogle API ile Watson API arasındaki temel farkın Watson ara yüzünün daha düzenli çıktılar döndürmesi ve SPARQL sorgularının uygulanabildiği alanının olduğu kanısına vardım. Aşağıda bazı ekran çıktıları ve Swoogle uygulamasının kaynak kodu verilmiştir. Kaynak Kod: package swoogle; import import import import import java.io.BufferedReader; java.io.InputStream; java.io.InputStreamReader; java.io.StringReader; java.util.ArrayList; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import import import import import import import import org.apache.commons.httpclient.HttpClient; org.apache.commons.httpclient.HttpStatus; org.apache.commons.httpclient.methods.GetMethod; org.w3c.dom.CharacterData; org.w3c.dom.Document; org.w3c.dom.Element; org.w3c.dom.NodeList; org.xml.sax.InputSource; public class Swoogle { public ArrayList<String> searchInSwoogle(String string1) { String request = "http://logos.cs.umbc.edu:8080/swoogle31/q?queryType=search_swd_ontology&se archString=" + string1 + "+" + "&key=demo"; String result = ""; try { // create an http client.. HttpClient client = new HttpClient(); GetMethod method = new GetMethod(request); // Send GET request int statusCode = client.executeMethod(method); if (statusCode != HttpStatus.SC_OK) { System.err.println("Method failed: " + method.getStatusLine()); } InputStream rstream = null; // Get the response body rstream = method.getResponseBodyAsStream(); BufferedReader br = new BufferedReader(new InputStreamReader( rstream)); String line; while ((line = br.readLine()) != null) { result = result + line; } br.close(); } catch (Exception e) { e.printStackTrace(); } return parseSwoogleXML(result); } public ArrayList<String> parseSwoogleXML(String xmlString) { ArrayList<String> arrURLs = new ArrayList<String>(); try { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); InputSource is = new InputSource(); is.setCharacterStream(new StringReader(xmlString)); Document doc = db.parse(is); NodeList nodes = doc .getElementsByTagName("wob:SemanticWebDocument"); // iterate, for (int i = 0; i < nodes.getLength(); i++) { Element element = (Element) nodes.item(i); NodeList ftype = element .getElementsByTagName("swoogle:hasFiletype"); Element line = (Element) ftype.item(0); NodeList fsize = element .getElementsByTagName("swoogle:hasLength"); Element line1 = (Element) fsize.item(0); String fileType = getCharacterDataFromElement(line); String tmpFileSize; tmpFileSize = getCharacterDataFromElement(line1); long fileSize; if (tmpFileSize.compareTo("-") != 0) { fileSize = Long.parseLong(tmpFileSize); } else { fileSize = 0; } if ((fileType.compareTo("owl") == 0 || fileType .compareTo("rdf") == 0) && fileSize < 65536) { arrURLs.add(element.getAttribute("rdf:about")); } } } catch (Exception e) { e.printStackTrace(); } return arrURLs; } public static String getCharacterDataFromElement(Element e) { org.w3c.dom.Node child = e.getFirstChild(); if (child instanceof CharacterData) { CharacterData cd = (CharacterData) child; return cd.getData(); } return "?"; } } package swoogle; import java.util.ArrayList; import java.util.Scanner; public class SwoogleMain { public static void main(String[] args) { System.out .println("1- Search"); // quite simple menu //just to test class System.out .println("2- Exit"); int ans = 0; do { System.out .println("Concept to search in Swoogle"); Scanner input = new Scanner(System.in); String keyword = input.nextLine(); // search the keyword ! find(keyword); System.out .println("1 to go on , 2 to quit\n"); Scanner input2 = new Scanner(System.in); ans = input2.nextInt(); } while (ans == 1); } // search function public static void find(String key) { ArrayList<String> toWrite = new ArrayList<String>(); Swoogle find = new Swoogle(); ArrayList<String> resultArray = find.searchInSwoogle(key); if (resultArray.isEmpty()) { System.out.println("keyword : " + key + "Not found... :("); } else { toWrite.add(key + " :" + resultArray.toString()); // System.out.println("keyword : " + key + " " + " ontologies: " + resultArray); } } } Agent kavramının sonuçları: (Ekran çıktıları) SwoogleAPI: WatsonAPI: (1307 sonuç, tüm sonuçları döndürür. Swoogle da keyler sınırlar konulmuş.)