sentence-transformers How to use buelfhood/SOCO-Java-PLBART-ST with sentence-transformers:
from sentence_transformers import SentenceTransformer
model = SentenceTransformer("buelfhood/SOCO-Java-PLBART-ST")
sentences = [
"\nimport java.io.*;\nimport java.net.*;\n\npublic class Copier\n{\n private URL target;\n\n public Copier( String fileName)\n {\n try\n {\n String line;\n BufferedReader ;\n\t BufferedWriter bout;\n target = new URL( \"http://www.cs.rmit.edu./students\");\n\t InputStream hm = target.openStream();\n\t HttpURLConnection urlcon = ( HttpURLConnection) target.openConnection();\n bf = new BufferedReader( new InputStreamReader( target.openStream()));\n\t bout = new BufferedWriter(new FileWriter(fileName));\n while((line = bf.readLine()) != null)\n {\n bout.write( line+\"\\n\"); \n }\n\t \n\t bout.print();\n }\n catch( Exception e)\n {\n System.out.println(\"Something wrong! \"+e);\n System.exit(0);\n }\n }\n public static void main (String[] args)\n {\n Copier c = new Copier(\"response.html\");\n }\n}\n\n \n \n\n \n\n\n \n\n\t\n",
"import java.io.*;\nimport java.net.*;\nimport java.util.*;\n\n\npublic class Dictionary\n{\n\tpublic static void main (String args[])\n\t{\n\t\t\n\t\t\n Calendar cal = Calendar.getInstance();\n Date now=cal.getTime();\n double startTime = now.getTime();\n\n\t\tString password=getPassword(startTime);\n\t\tSystem.out.println(\"The password is \" + password);\n\t}\n\n\tpublic static String getPassword(double startTime)\n\t{\n\t\tString password=\"\";\n\t\tint requests=0;\n\n\t\ttry\n\t\t{\n\t\t\t\n\t\t\tFileReader fRead = new FileReader(\"/usr/share/lib/dict/words\");\n\t\t\tBufferedReader buf = new BufferedReader(fRead);\n\n\t\t\tpassword=buf.readLine();\n\n\t\t\twhile (password != null)\n\t\t\t{\n\t\t\t\t\n\t\t\t\tif (password.length()<=3)\n\t\t\t\t{\n\t\t\t\t\trequests++;\n\t\t\t\t\tif (testPassword(password, startTime, requests))\n\t\t\t\t\t\treturn password;\n\t\t\t\t}\n\n\t\t\t\tpassword = buf.readLine();\n\n\t\t\t}\n\t\t}\n\t\tcatch (IOException ioe)\n\t\t{\n\n\t\t}\n\n\t\treturn password;\n\t}\n\n\tprivate static boolean testPassword(String password, double startTime, int requests)\n\t{\n\t\ttry\n\t\t{\n\t\t\t\n\t\t\t\n\t\t\tURL url=new URL(\"http://sec-crack.cs.rmit.edu./SEC/2/\");\n\n\t\t\tHttpURLConnection connection;\n\n \t\tString userPassword = \":\" + password;\n\n \t\t\n \t\tString encoding = new url.misc.BASE64Encoder().encode (userPassword.getBytes());\n\n\t\t\ttry\n\t\t\t{\n\t\t\t\t\n\t\t\t\tconnection = (HttpURLConnection) url.openConnection();\n\t\t\t\t\n\t\t\t\tconnection.setRequestProperty(\"Authorization\", \" \" + encoding);\n\n\t\t\t\t\n\t\t\t\tint status=connection.getResponseCode();\n\n\t\t\t\tSystem.out.println(password + requests);\n\n\t\t\t\tif (status==200)\n\t\t\t\t{\n\t\t\t\t\tSystem.out.println(\"It took \" + getTime(startTime) + \" milliseconds find the password.\");\n\t\t\t\t\tSystem.out.println(\" were \" + requests + \" requests .\");\n\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\n\t\t\t\treturn false;\n\n\t\t\t}\n\n\t\t\tcatch (IOException ioe)\n\t\t\t{\n\t\t\t\tSystem.out.print(ioe);\n\t\t\t\treturn false;\n\t\t\t}\n\n\t\t}\n\n\t\tcatch (IOException MalformedURLException)\n\t\t{\n\t\t\tSystem.out.print(\"Invalid URL\");\n\t\t\treturn false;\n\t\t}\n\t}\n\n\n\tprivate static double getTime(double startTime)\n\t{\n\t\t\n\t\t\n Calendar cal = Calendar.getInstance();\n Date now=cal.getTime();\n double endTime = now.getTime();\n\n return endTime-startTime;\n\n\t}\n\n}\n",
"import java.io.*;\nimport java.net.*;\nimport java.util.*;\nimport java.*;\n\n\npublic class WatchDog {\n\n\npublic static final int interval = 79200000;\n\npublic static void main(String[] args) {\n WatchDog wd = new WatchDog();\n Thread thread = new Thread();\n URLConnection conn = null;\n DataInputStream data = null;\n DataInputStream in = null;\n String line;\n String lines;\n String buffer = new String();\n String buffers = new String();\n String url = new String(\"http://www.cs.rmit.edu./students/\");\n boolean change;\n\ttry{\n\tURL myurl = new URL(url);\n conn = myurl.openConnection();\n conn.connect();\n Object content = null;\n \n System.out.println(\"Connection opened......\");\n System.out.println(\"Retrieving data from URL\");\n data = new DataInputStream(new BufferedInputStream(conn.getInputStream()));\n System.out.println(\" data from the URL......\");\n content = myurl.getContent();\n BufferedReader reader = null;\n\treader = new BufferedReader(new InputStreamReader((InputStream) content));\n\n \n while ((line = data.readLine()) != null)\n\n {\n System.out.println(line);\n FileWriter outnew = new FileWriter(\"watchdogresult.html\");\n outnew.write(line);\n }\n System.out.println(\"Waiting for any change....\");\n thread.sleep(79200000);\n conn = myurl.openConnection();\n conn.connect();\n in = new DataInputStream(new BufferedInputStream(conn.getInputStream()));\n while ((lines = in.readLine()) != null)\n {\n\n\t FileWriter newf = new FileWriter(\"watchdogresult.tmp\");\n newf.write(buffers);\n }\n\tchange = true;\n if(change);\n else{\n\tchange = false;\n \n\twd.mail();\n\t}\n}\n catch (InterruptedException e) {}\n catch (IOException e) {\n e.printStackTrace();\n String r = new String(e.getMessage());\n if ( r != null)\n {\n System.out.println(\"Message :\" +r);\n }\n else\n System.out.println(\"Other problems\");\n }\n }\n\n\npublic void mail(){\n\n try {\n\n String from = new String(\"Watchdog Reporter\");\n String email = new String(\"@cs.rmit.edu.\");\n String subject = new String(\" is a change in \");\n\n \n URL u = new URL(\"mailto:\" + email);\n URLConnection c = u.openConnection();\n c.setDoInput(false);\n c.setDoOutput(true);\n System.out.println(\"Connecting...\");\n System.out.flush();\n c.connect();\n PrintWriter out =\n new PrintWriter(new OutputStreamWriter(c.getOutputStream()));\n\n \n out.println(\"From: \\\"\" + from + \"\\\" <\" +\n System.getProperty(\"user.name\") + \"@\" +\n InetAddress.getLocalHost().getHostName() + \">\");\n out.println(\": \" );\n out.println(\"Subject: \" + subject);\n out.println(); \n\n \n String line = new String(\"Watchdog observe that is a change in the web .\");\n out.close();\n System.out.println(\"Message sent.\");\n System.out.flush();\n }\n catch (Exception e) {\n System.err.println(e);\n }\n\n }\n\n}\n\n",
"\n\n\n\n \n\n\nclass BasicAuth {\n\n public BasicAuth() {}\n\n\n private static byte[] cvtTable = {\n (byte)'A', (byte)'B', (byte)'C', (byte)'D', (byte)'E',\n (byte)'F', (byte)'G', (byte)'H', (byte)'I', (byte)'J',\n (byte)'K', (byte)'L', (byte)'M', (byte)'N', (byte)'O',\n (byte)'P', (byte)'Q', (byte)'R', (byte)'S', (byte)'T',\n (byte)'U', (byte)'V', (byte)'W', (byte)'X', (byte)'Y',\n (byte)'Z',\n (byte)'a', (byte)'b', (byte)'c', (byte)'d', (byte)'e',\n (byte)'f', (byte)'g', (byte)'h', (byte)'i', (byte)'j',\n (byte)'k', (byte)'l', (byte)'m', (byte)'n', (byte)'o',\n (byte)'p', (byte)'q', (byte)'r', (byte)'s', (byte)'t',\n (byte)'u', (byte)'v', (byte)'w', (byte)'x', (byte)'y',\n (byte)'z',\n (byte)'0', (byte)'1', (byte)'2', (byte)'3', (byte)'4',\n (byte)'5', (byte)'6', (byte)'7', (byte)'8', (byte)'9',\n (byte)'+', (byte)'/'\n };\n\n static String encode(String name,\n String passwd) {\n byte input[] = (name + \":\" + passwd).getBytes();\n byte[] output = new byte[((input.length / 3) + 1) * 4];\n int ridx = 0;\n int chunk = 0;\n\n for (int i = 0; i < input.length; i += 3) {\n int left = input.length - i;\n\n\n if (left > 2) {\n chunk = (input[i] << 16)|\n (input[i + 1] << 8) |\n input[i + 2];\n output[ridx++] = cvtTable[(chunk&0xFC0000)>>18];\n output[ridx++] = cvtTable[(chunk&0x3F000) >>12];\n output[ridx++] = cvtTable[(chunk&0xFC0) >> 6];\n output[ridx++] = cvtTable[(chunk&0x3F)];\n } else if (left == 2) {\n\n chunk = (input[i] << 16) |\n (input[i + 1] << 8);\n output[ridx++] = cvtTable[(chunk&0xFC0000)>>18];\n output[ridx++] = cvtTable[(chunk&0x3F000) >>12];\n output[ridx++] = cvtTable[(chunk&0xFC0) >> 6];\n output[ridx++] = '=';\n } else {\n\n chunk = input[i] << 16;\n output[ridx++] = cvtTable[(chunk&0xFC0000)>>18];\n output[ridx++] = cvtTable[(chunk&0x3F000) >>12];\n output[ridx++] = '=';\n output[ridx++] = '=';\n }\n }\n return new String(output);\n }\n}"
]
embeddings = model.encode(sentences)
similarities = model.similarity(embeddings, embeddings)
print(similarities.shape)
# [4, 4]