Beispiel #1
0
 private static void AddEntries(java.util.zip.ZipFile file, string rootDirectory, string[] newFiles, bool flattenHierarchy)
 {
     string destFileName = file.getName();
     string tempFileName = Path.GetTempFileName();
     ZipOutputStream destination = new ZipOutputStream(new FileOutputStream(tempFileName));
     try
     {
         CopyEntries(file, destination);
         if (newFiles != null)
         {
             foreach (string str3 in newFiles)
             {
                 string directoryName;
                 if (flattenHierarchy)
                 {
                     directoryName = Path.GetDirectoryName(str3);
                 }
                 else if (rootDirectory == null)
                 {
                     directoryName = Path.GetPathRoot(str3);
                 }
                 else
                 {
                     directoryName = rootDirectory;
                 }
                 directoryName = directoryName + @"\";
                 ZipEntry ze = new ZipEntry(str3.Remove(0, directoryName.Length));
                 ze.setMethod(8);
                 destination.putNextEntry(ze);
                 try
                 {
                     FileInputStream source = new FileInputStream(str3);
                     try
                     {
                         CopyStream(source, destination);
                     }
                     finally
                     {
                         source.close();
                     }
                 }
                 finally
                 {
                     destination.closeEntry();
                 }
             }
         }
     }
     finally
     {
         destination.close();
     }
     file.close();
     System.IO.File.Copy(tempFileName, destFileName, true);
     System.IO.File.Delete(tempFileName);
 }
 public static byte[] getBytesFromFileJava(string filePath)
 {
     FileInputStream fis = new FileInputStream (new java.io.File (filePath));
     BufferedInputStream bis = new BufferedInputStream(fis);
     int numByte = bis.available();
     byte[] buff = new byte[numByte];
     bis.read(buff, 0, numByte);
     bis.close ();
     fis.close ();
     return buff;
 }
Beispiel #3
0
        public void TestTikaAutodetect()
        {
            Tika tika = new Tika();
            File xpsFile = new File("samples\\test1.xps");
		    if (!xpsFile.isFile())
			    throw new Exception(xpsFile.getName() + " does not exists.");

            using (InputStream inputStream = new FileInputStream(xpsFile))
            {
                Metadata metadata = new Metadata();

                string mimeType = tika.detect(inputStream, metadata);
                Assert.AreEqual("application/x-tika-ooxml", mimeType);

                inputStream.close();
            }
        }
 private SentenceDetectorME PrepareSentenceDetector()
 {
     //TODO[danielcamargo]: we need to find/train the model in spanish
     var sentModelStream =
         new FileInputStream(string.Format(@"Models\{0}-sent.bin", _language == "es" ? "pt" : _language));
     var sentModel = new SentenceModel(sentModelStream);
     sentModelStream.close();
     return new SentenceDetectorME(sentModel);
 }
 private TokenizerME PrepareTokenizer()
 {
     //TODO[danielcamargo]: we need to find/train the model in spanish
     var tokenInputStream =
         new FileInputStream(string.Format(@"Models\{0}-token.bin", _language == "es" ? "pt" : _language));
     var tokenModel = new TokenizerModel(tokenInputStream);
     tokenInputStream.close();
     return new TokenizerME(tokenModel);
 }
        private POSTaggerME PreparePosTagger()
        {
            var model = string.Format(@"Models\{0}-pos-maxent.bin", _language);

            var posModelStream = new FileInputStream(model);
            var posModel = new POSModel(posModelStream);
            posModelStream.close();
            return new POSTaggerME(posModel);
        }
 private NameFinderME PrepareNameFinder()
 {
     var modelInputStream = new FileInputStream(_nameFinderModelPath);
     var model = new TokenNameFinderModel(modelInputStream);
     modelInputStream.close();
     return new NameFinderME(model);
 }
Beispiel #8
0
        public String chooseSentenceMenu()
        {
            int userInputNumber = 0;
            string userChoosenSentence = "";
            System.Console.WriteLine("Choose a sentence to use from your current text");
            System.Console.WriteLine("Must be a space between each sentence");
            try
            {
                java.io.File file = new java.io.File("C:\\en-sent.bin");
                java.io.InputStream modelIn = new FileInputStream("C:\\Users\\jcoleman\\Documents\\Capstone\\jcoleman_Capstone\\Code\\NEWCHATBOT\\ConsoleBot\\ConsoleBot\\en-sent.bin");
                SentenceModel model = new SentenceModel(modelIn);
                SentenceDetectorME sentenceDetector = new SentenceDetectorME(model);

                string text = "";
                FileText = System.IO.File.ReadAllLines(FilePath);

                for (int i = 0; i < FileText.Length; i++)
                {
                    text += FileText[i];
                }

                string[] sentences = sentenceDetector.sentDetect(text);

                for(int s = 0;s < sentences.Length;s++)
                {
                    System.Console.WriteLine((s+1) +" : " +sentences[s]);
                }

                string userInput = System.Console.ReadLine();
                userInputNumber = int.Parse(userInput);

                userChoosenSentence = sentences[userInputNumber - 1];
                modelIn.close();
            }
            catch(Exception e)
            {
                System.Console.WriteLine(e.Message);
            }

            return userChoosenSentence;
        }
        public int run(String[] arguments) {
            sourceFiles.clear();
            if (!handleArguments(arguments)) {
                return 1;
            }
            
            var t0 = System.nanoTime();
            
			try {
				var results = new Compiler().compileFromFiles(parameters, sourceFiles.toArray(new File[sourceFiles.size()]));
				var hasErrors = false;
				foreach (var error in results.Errors) {
					var filename = error.Filename;
					if (filename != null) {
						System.out.print(new File(error.Filename).getAbsolutePath());
					} else {
						System.out.print("Unknown source");
					}
					if (error.Line > 0) {
						System.out.print(" (");
						System.out.print(error.Line);
						if (error.Column > 0) {
							System.out.print(", ");
							System.out.print(error.Column);
						}
						System.out.print(")");
					}
					if (error.Level == 0) {
						hasErrors = true;
						System.out.print(" error ");
					} else {
						System.out.print(" warning ");
					}
					System.out.print(error.Id);
					System.out.print(": ");
					System.out.println(error.Message);
				}
				if (!hasErrors) {
					var outputFile = new File(outputPath);
					if (outputFile.isDirectory() || outputPath.endsWith("\\") || outputPath.endsWith("/")) {
						foreach (var e in results.ClassFiles.entrySet()) {
							var file = new File(outputFile, e.Key.replace('.', '/') + ".class");
							var dir = file.getParentFile();
							if (!dir.exists()) {
								dir.mkdirs();
							}
							using (var s = new FileOutputStream(file)) {
								s.write(e.Value);
							}
						}
					} else {
						var destination = outputPath;
						if (PathHelper.getExtension(destination).length() == 0) {
							destination += ".jar";
						}
						using (var zipStream = new ZipOutputStream(new FileOutputStream(destination))) {
							if (manifestPath != null) {
								var zipEntry = new ZipEntry("META-INF/MANIFEST.MF");
								zipStream.putNextEntry(zipEntry);
								var buffer = new byte[4096];
								var inputStream = new FileInputStream(manifestPath);
								int read;
								while ((read = inputStream.read(buffer)) != -1) {
									zipStream.write(buffer, 0, read);
								}
								inputStream.close();
							}
							if (resourcesPath != null) {
								var rootDir = new File(resourcesPath);
								foreach (var content in rootDir.list()) {
									var file = new File(rootDir, content);
									if (file.isDirectory()) {
										exploreDirectory(zipStream, "", file);
									} else {
										addEntry(zipStream, "", file);
									}
								}
							}
							foreach (var e in results.ClassFiles.entrySet()) {
								var zipEntry = new ZipEntry(e.Key.replace('.', '/') + ".class");
								zipStream.putNextEntry(zipEntry);
								zipStream.write(e.Value);
							}
						}
					}
					System.out.println();
					System.out.println(String.format("%d class(es) successfully generated in %.2fs",
						results.classFiles.size(), (System.nanoTime() - t0) / 1e9));
					return 0;
				} else {
					System.out.println();
					System.out.println("Compilation failed");
					return 1;
				}
			} catch (TypeLoadException e) {
				System.out.println("Cannot find type " + e.TypeName + ". The class is missing from the classpath.");
				System.out.println("Compilation failed");
				return 1;
			}
        }