<commit_before>/*******************************************************************************
 * Copyright (c) 2007-2009  <NAME>
 *               2008-2009  <NAME> <<EMAIL>>
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * www.eclipse.org—epl-v10.html <http://www.eclipse.org/legal/epl-v10.html>
 * 
 * Contact: http://www.bioclipse.net/
 ******************************************************************************/
package net.bioclipse.onssolubility.business;

import java.io.ByteArrayOutputStream;

import net.bioclipse.core.ResourcePathTransformer;
import net.bioclipse.core.business.BioclipseException;
import net.bioclipse.managers.business.IBioclipseManager;
import net.bioclipse.onssolubility.preferences.PreferenceConstants;
import ons.solubility.rdf.ConvertToRDF;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.Preferences;

public class SolubilityManager implements IBioclipseManager {

    protected SolubilityManagerFactory factory;

    protected SolubilityManagerFactory getFactory() throws Exception {
        if (factory == null) {
            factory = new SolubilityManagerFactory();
        }
        return factory;
    }

    public String getManagerName() {
        return "solubility";
    }

    public String downloadAsRDF(String filename) throws BioclipseException {
        IFile file = ResourcePathTransformer.getInstance().transform(filename);
        downloadAsRDF(file, null);
        return filename;
    }

    public IFile downloadAsRDF(IFile file, IProgressMonitor monitor)
        throws BioclipseException {
        ByteArrayOutputStream output = new ByteArrayOutputStream();
        try {
            ConvertToRDF convertor = new ConvertToRDF();
            Preferences prefs = Activator.getDefault().getPluginPreferences();
            convertor.processData(
                prefs.getString(PreferenceConstants.GOOGLE_USERNAME),
                prefs.getString(PreferenceConstants.GOOGLE_PASSWORD)
            );
            convertor.write(output);<commit_msg>Now save the content actually to file<commit_after>/*******************************************************************************
 * Copyright (c) 2007-2009  <NAME>
 *               2008-2009  <NAME> <<EMAIL>>
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * www.eclipse.org—epl-v10.html <http://www.eclipse.org/legal/epl-v10.html>
 * 
 * Contact: http://www.bioclipse.net/
 ******************************************************************************/
package net.bioclipse.onssolubility.business;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;

import net.bioclipse.core.ResourcePathTransformer;
import net.bioclipse.core.business.BioclipseException;
import net.bioclipse.managers.business.IBioclipseManager;
import net.bioclipse.onssolubility.preferences.PreferenceConstants;
import ons.solubility.rdf.ConvertToRDF;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.Preferences;

public class SolubilityManager implements IBioclipseManager {

    protected SolubilityManagerFactory factory;

    protected SolubilityManagerFactory getFactory() throws Exception {
        if (factory == null) {
            factory = new SolubilityManagerFactory();
        }
        return factory;
    }

    public String getManagerName() {
        return "solubility";
    }

    public String downloadAsRDF(String filename) throws BioclipseException {
        IFile file = ResourcePathTransformer.getInstance().transform(filename);
        downloadAsRDF(file, null);
        return filename;
    }

    public IFile downloadAsRDF(IFile file, IProgressMonitor monitor)
        throws BioclipseException {
        if (file.exists()) {
            throw new BioclipseException("File already exists!");
        }

        ByteArrayOutputStream output = new ByteArrayOutputStream();
        try {
            ConvertToRDF convertor = new ConvertToRDF();
            Preferences prefs = Activator.getDefault().getPluginPreferences();
            convertor.processData(
                prefs.getString(PreferenceConstants.GOOGLE_USERNAME),
                prefs.getString(PreferenceConstants.GOOGLE_PASSWORD)
            );
            convertor.write(output);
            file.create(
                new ByteArrayInputStream(output.toByteArray()),
                false,
                monitor
            );
{'fraction_non_alphanumeric': 0.144375, 'fraction_numerical': 0.009166666666666667, 'mean_word_length': 3.478544776119403, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 6, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5836339', 'n_tokens_mistral': 1315, 'n_tokens_neox': 1213, 'n_words': 267}