Java tutorial
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package matrix; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.UnsupportedEncodingException; import java.text.DecimalFormat; import java.util.ArrayList; import org.json.simple.JSONArray; import org.json.simple.JSONObject; import org.json.simple.parser.JSONParser; import org.json.simple.parser.ParseException; /** * * @author nSabri */ public class CreateUrlMatrix { private String urlInputPath; private String urlOutputPath; public void urlMatrix() throws UnsupportedEncodingException, FileNotFoundException, IOException, ParseException { CosSim cossim = new CosSim(); JSONParser jParser = new JSONParser(); BufferedReader in = new BufferedReader(new InputStreamReader( new FileInputStream("/Users/nSabri/Desktop/tweetMatris/userTweetsUrls.json"), "ISO-8859-9")); JSONArray a = (JSONArray) jParser.parse(in); File fout = new File("/Users/nSabri/Desktop/urlMatris.csv"); FileOutputStream fos = new FileOutputStream(fout); BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(fos)); for (int i = 0; i < a.size(); i++) { for (int j = 0; j < a.size(); j++) { JSONObject tweet1 = (JSONObject) a.get(i); JSONObject tweet2 = (JSONObject) a.get(j); String tweetUrl1 = tweet1.get("title").toString() + tweet1.get("meta").toString(); System.out.println(tweetUrl1); String tweetUrl2 = tweet2.get("title").toString() + tweet1.get("meta").toString(); System.out.println(tweetUrl2); double CosSimValue = cossim.Cosine_Similarity_Score(tweetUrl1, tweetUrl2); CosSimValue = Double.parseDouble(new DecimalFormat("##.###").format(CosSimValue)); bw.write(Double.toString(CosSimValue) + ", "); } bw.newLine(); } bw.close(); } public String getUrlInputPath() { return urlInputPath; } public void setUrlInputPath(String urlInputPath) { this.urlInputPath = urlInputPath; } public String getUrlOutputPath() { return urlOutputPath; } public void setUrlOutputPath(String urlOutputPath) { this.urlOutputPath = urlOutputPath; } }