Loads a mapping from word to {@link TernaryVector} from the file
979645
@SuppressWarnings("unchecked")
    public static Map<String,TernaryVector> load(File indexVectorFile) {
        try {
            FileInputStream fis = new FileInputStream(indexVectorFile);
            ObjectInputStream inStream = new ObjectInputStream(fis);
            Map<String, TernaryVector> vectorMap = 
                (Map<String, TernaryVector>) inStream.readObject();
            inStream.close();
            return vectorMap;
        } catch (IOException ioe) {
            throw new IOError(ioe);
        } catch (ClassNotFoundException cnfe) {
            throw new Error(cnfe);
        }
    }
1089712
@Override
    public boolean loadValuesFrom(String filename) {
        String yamlStr = textIn(filename);
        Object y = yaml.load(yamlStr);
        if (y instanceof Map) {
            getCurrentValues().putAll((Map) y);
        } else {
            getCurrentValues().put("elements", y);
        }
        return true;
    }
1268164
private Matrix loadText(InputStream fileStream) throws IOException {
        Matrix matrix = null;

        BufferedReader br = 
                new BufferedReader(new InputStreamReader(fileStream));
        String line = br.readLine();
        if (line == null)
            throw new IOException("Empty .sspace file");
            // Strip off the 4-byte (2 char) header
        String[] dimensions = line.split("\\s");
        int rows = Integer.parseInt(dimensions[0]);
        int columns = Integer.parseInt(dimensions[1]);
        int index = 0;
        
        // reusable array for writing rows into the matrix
        double[] row = new double[columns];
        
        matrix = new ArrayMatrix(rows, columns);

        while ((line = br.readLine()) != null) {
            if (index >= rows)
                throw new IOException("More rows than specified");
            String[] termVectorPair = line.split("\\|");
            String[] values = termVectorPair[1].split("\\s");
            termToIndex.put(termVectorPair[0], index);
            if (values.length != columns) {
                throw new IOException(
                            "improperly formated semantic space file");
            }
            for (int c = 0; c < columns; ++c) {
                double d = Double.parseDouble(values[c]);
                row[c] = d;
                // matrix.set(index, c, d);
            }
            matrix.setRow(index, row);
            index++;
        }
        if (index != rows)
            throw new IOException(String.format(
                "Expected %d rows; saw %d", rows, index));
        return matrix;    
    }
173000
public Object loadProvUnknownGraph(String filename) {

        try {
            Utility u = new Utility();
            CommonTree tree = u.convertASNToTree(filename);
            Object o = u.convertTreeToJavaBean(tree, pFactory);
            if (o != null) {
                return o;
            }
        } catch (RecognitionException t1) {
            // OK, we failed, let's try next format.
        } catch (IOException e) {
            // OK, we failed, let's try next format.
        }
        try {
            File in = new File(filename);
            ProvDeserialiser deserial = ProvDeserialiser
                    .getThreadProvDeserialiser();
            Document c = deserial.deserialiseDocument(in);
            if (c != null) {
                return c;
            }
        } catch (JAXBException t2) {
            // OK, we failed, let's try next format.
        }

        try {
            Document o = new org.openprovenance.prov.json.Converter(pFactory)
                    .readDocument(filename);
            if (o != null) {
                return o;
            }
        } catch (IOException e) {
            // OK, we failed, let's try next format.

        }
        try {
            org.openprovenance.prov.rdf.Utility rdfU = new org.openprovenance.prov.rdf.Utility(
                    pFactory, onto);
            Document doc = rdfU.parseRDF(filename);
            if (doc != null) {
                return doc;
            }
        } catch (RDFParseException e) {
        } catch (RDFHandlerException e) {
        } catch (IOException e) {
        } catch (JAXBException e) {
        }
        System.out.println("Unparseable format " + filename);
        throw new UnsupportedOperationException();

    }
1166707
public static SimpleDataSet loadArffFile(Reader input, DataStore store) 
    {
        DataStore list = store.emptyClone();
        DoubleList weights = new DoubleList();
        
        BufferedReader br = new BufferedReader(input);
        
        int numOfVars = 0;
        int numReal = 0;
        List<Boolean> isReal = new ArrayList<>();
        List<String> variableNames = new ArrayList<>();
        List<HashMap<String, Integer>> catVals = new  ArrayList<>();
        String line = null;
        CategoricalData[] categoricalData = null;
        try
        {
            boolean atData = false;
            while( (line = br.readLine()) != null )
            {
                if(line.startsWith("%") || line.trim().isEmpty())
                    continue;///Its a comment, skip
                
                line = line.trim();
                
                if(line.startsWith("@") && !atData)
                {
                    line = line.substring(1).toLowerCase();
                    
                    
                    if(line.toLowerCase().startsWith("data"))
                    {
                        categoricalData = new CategoricalData[numOfVars-numReal];
                        
                        int k = 0;
                        for(int i = 0; i < catVals.size(); i++)
                        {
                            if(catVals.get(i) != null)
                            {
                                categoricalData[k] = new CategoricalData(catVals.get(i).size());
                                categoricalData[k].setCategoryName(variableNames.get(i));
                                for(Entry<String, Integer> entry : catVals.get(i).entrySet())
                                    categoricalData[k].setOptionName(entry.getKey(), entry.getValue());
                                k++;
                            }
                        }
                        
                        //prept to start reading in data
                        list.setNumNumeric(numReal);
                        list.setCategoricalDataInfo(categoricalData);
                        atData = true;
                        continue;
                    }
                    else if(!line.toLowerCase().startsWith("attribute"))
                        continue;
                    numOfVars++;
                    line = line.substring("attribute".length()).trim();//Remove the space, it could be multiple spaces
                    
                    String variableName = null;
                    line = line.replace("\t", " ");
                    if(line.startsWith("'"))
                    {
                        Pattern p = Pattern.compile("'.+?'");
                        Matcher m = p.matcher(line);
                        m.find();
                        variableName = nameTrim(m.group());
                                
                        line = line.replaceFirst("'.+?'", "placeHolder");
                    }
                    else
                        variableName = nameTrim(line.trim().replaceAll("\\s+.*", ""));
                    variableNames.add(variableName);
                    String[] tmp = line.split("\\s+", 2);
                    
                    
                    if(tmp[1].trim().equals("real") || tmp[1].trim().equals("numeric") || tmp[1].trim().startsWith("integer"))
                    {
                        numReal++;
                        isReal.add(true);
                        catVals.add(null);
                    }
                    else//Not correct, but we arent supporting anything other than real and categorical right now
                    {
                        isReal.add(false);
                        String cats = tmp[1].replace("{", "").replace("}", "").trim();
                        if(cats.endsWith(","))
                            cats = cats.substring(0, cats.length()-1);
                        String[] catValsRaw =  cats.split(",");
                        HashMap<String, Integer> tempMap = new HashMap<String, Integer>();
                        for(int i = 0; i < catValsRaw.length; i++)
                        {
                            catValsRaw[i] = nameTrim(catValsRaw[i]);
                            tempMap.put(catValsRaw[i], i);
                        }
                        catVals.add(tempMap);
                    }
                }
                else if(atData && !line.isEmpty())
                {
                    double weight = 1.0;
                    String[] tmp = line.split(",");
                    if(tmp.length != isReal.size())
                    {
                        String s = tmp[isReal.size()];
                        if(tmp.length == isReal.size()+1)//{#} means the # is the weight
                        {
                            if(!s.matches("\\{\\d+(\\.\\d+)?\\}"))
                                throw new RuntimeException("extra column must indicate a data point weigh in the form of \"{#}\", instead bad token " + s + " was found");
                            weight = Double.parseDouble(s.substring(1, s.length()-1));
                        }
                        else
                        {
                            throw new RuntimeException("Column had " + tmp.length + " values instead of " + isReal.size());
                        }
                    }
                        
                    DenseVector vec = new DenseVector(numReal);
                    
                    int[] cats = new int[numOfVars - numReal];
                    int k = 0;//Keeping track of position in cats
                    for(int i  = 0; i < isReal.size(); i++)
                    {
                        String val_string = tmp[i].trim();
                        if (isReal.get(i))
                            if (val_string.equals("?"))//missing value, indicated by NaN
                                vec.set(i - k, Double.NaN);
                            else
                                vec.set(i - k, Double.parseDouble(val_string));
                        else//Categorical
                        {
                            tmp[i] = nameTrim(tmp[i]).trim().toLowerCase();
                            if(tmp[i].equals("?"))//missing value, indicated by -1
                                cats[k++] = -1;
                            else
                                cats[k++] = catVals.get(i).get(tmp[i]);
                        }
                    }
                    
                    list.addDataPoint(new DataPoint(vec, cats, categoricalData)); 
                    weights.add(weight);
                }
            }
        }
        catch (IOException ex)
        {
            
        }
        
        SimpleDataSet dataSet =  new SimpleDataSet(list);
        for(int i = 0; i < weights.size(); i++)
            dataSet.setWeight(i, weights.getD(i));
        int k = 0;
        for (int i = 0; i < isReal.size(); i++)
            if (isReal.get(i))
                dataSet.setNumericName(variableNames.get(i), k++);
        
        return dataSet;
    }
1232092
@GwtIncompatible("com.google.common.base.Splitter.onPattern()")
  public static VariableMap fromBytes(byte[] bytes) throws ParseException {
    String string = new String(bytes, UTF_8);
    ImmutableMap.Builder<String, String> map = ImmutableMap.builder();
    int startOfLine = 0;
    while (startOfLine < string.length()) {
      int newLine = string.indexOf('\n', startOfLine);
      if (newLine == -1) {
        newLine = string.length();
      }
      int endOfLine = newLine;
      if (string.charAt(newLine - 1) == '\r') {
        newLine--;
      }
      String line = string.substring(startOfLine, newLine);
      startOfLine = endOfLine + 1; // update index for next iteration
      if (line.isEmpty()) {
        continue;
      }
      int pos = findIndexOfUnescapedChar(line, SEPARATOR);
      if (pos <= 0) {
        throw new ParseException("Bad line: " + line, 0);
      }
      map.put(
          unescape(line.substring(0, pos)),
          pos == line.length() - 1 ? "" : unescape(line.substring(pos + 1)));
    }
    return new VariableMap(map.build());
  }
86134
private static String getFromEnvFile(String varname, String filename)
	{
		try
		{
			String	code = readFile(filename);
        	StringTokenizer stk = new StringTokenizer(code, "\n");
	        while (stk.hasMoreTokens())
        	{
            	String line = stk.nextToken().trim();
				if (line.startsWith("#")==false)
				{
					int	pos = line.indexOf(varname+"=");
					if (pos>=0)	//	Var found
						return line.substring(pos+varname.length()+1);
				}
			}
		}
		catch(Exception e) {
			//System.err.println(e);
		}
		return null;
	}
230662
def load(cls, sc, path):
        
        jmodel = sc._jvm.org.apache.spark.mllib.feature \
            .Word2VecModel.load(sc._jsc.sc(), path)
        model = sc._jvm.org.apache.spark.mllib.api.python.Word2VecModelWrapper(jmodel)
        return Word2VecModel(model)
694069
@Scope(DocScope.IO)
    public <T> XBAutoMap<T> readAsMapOf(final Class<T> valueType) throws IOException {
        DefaultXPathBinder.validateEvaluationType(valueType);
        final Class<?> resourceAwareClass = ReflectionHelper.getDirectCallerClass();
        Document document = IOHelper.getDocumentFromURL(projector.config().createDocumentBuilder(), url, requestProperties, resourceAwareClass);
        InvocationContext invocationContext = new InvocationContext(null, null, null, null, null, valueType, projector);
        return new AutoMap<T>(document, invocationContext, valueType);
    }
1178967
private static DataSet loadG(Reader reader, double sparseRatio, int vectorLength, boolean classification, DataStore store) throws IOException
    {
        StringBuilder processBuffer = new StringBuilder(20);
        StringBuilder charBuffer = new StringBuilder(1024);
        char[] buffer = new char[1024];
        DataStore sparceVecs = store.emptyClone();
        sparceVecs.setCategoricalDataInfo(new CategoricalData[0]);
        /**
         * The category "label" for each value loaded in
         */
        List<Double> labelVals = new DoubleList();
        Map<Double, Integer> possibleCats = new HashMap<>();
        int maxLen= 1;
        
        STATE state = STATE.INITIAL;
        int position = 0;
        SparseVector tempVec = new SparseVector(1, 1);
        /**
         * The index that we have parse out of a non zero pair
         */
        int indexProcessing = -1;
        while(true)
        {
            
            while(charBuffer.length()-position <= 1)//make sure we have chars to handle
            {
                //move everything to the front
                charBuffer.delete(0, position);
                position = 0;
                
                int read = reader.read(buffer);
                if(read < 0)
                    break;
                charBuffer.append(buffer, 0, read);
            }
            
            if(charBuffer.length()-position == 0)//EOF, no more chars
            {
                if(state == STATE.LABEL)//last line was empty
                {
                    double label = Double.parseDouble(processBuffer.toString());

                    if (!possibleCats.containsKey(label) && classification)
                        possibleCats.put(label, possibleCats.size());
                    labelVals.add(label);
                    
                    sparceVecs.addDataPoint(new DataPoint(new SparseVector(maxLen, 0)));
                }
                else if(state == STATE.WHITESPACE_AFTER_LABEL)//last line was empty, but we have already eaten the label
                {
                    sparceVecs.addDataPoint(new DataPoint(new SparseVector(maxLen, 0)));
                }
                else if(state == STATE.FEATURE_VALUE || state == STATE.WHITESPACE_AFTER_FEATURE)//line ended after a value pair
                {
                    //process the last value pair & insert into vec
                    double value = StringUtils.parseDouble(processBuffer, 0, processBuffer.length());
                    processBuffer.delete(0, processBuffer.length());

                    maxLen = Math.max(maxLen, indexProcessing+1);
                    tempVec.setLength(maxLen);
                    if (value != 0)
                        tempVec.set(indexProcessing, value);
                    sparceVecs.addDataPoint(new DataPoint(tempVec.clone()));
                }
                else if(state == STATE.NEWLINE)
                {
                    //nothing to do and everything already processed, just return
                    break;
                }
                else
                    throw new RuntimeException();
                //we may have ended on a line, and have a sparse vec to add before returning
                break;
            }
            
            char ch = charBuffer.charAt(position);
            switch(state)
            {
                case INITIAL:
                    state = STATE.LABEL;
                    break;
                case LABEL:
                    if (Character.isDigit(ch)  || ch == '.' || ch == 'E' || ch == 'e' || ch == '-' || ch == '+')
                    {
                        processBuffer.append(ch);
                        position++;
                    }
                    else if (Character.isWhitespace(ch))//this gets spaces and new lines
                    {
                        double label = Double.parseDouble(processBuffer.toString());

                        if (!possibleCats.containsKey(label) && classification)
                            possibleCats.put(label, possibleCats.size());
                        labelVals.add(label);

                        //clean up and move to new state
                        processBuffer.delete(0, processBuffer.length());
                        
                        if (ch == '\n' || ch == '\r')//empty line, so add a zero vector
                        {
                            tempVec.zeroOut();
                            sparceVecs.addDataPoint(new DataPoint(new SparseVector(maxLen, 0)));
                            state = STATE.NEWLINE;
                        }
                        else//just white space
                        {
                            tempVec.zeroOut();
                            state = STATE.WHITESPACE_AFTER_LABEL;
                        }
                    }
                    else
                        throw new RuntimeException("Invalid LIBSVM file");
                    break;
                case WHITESPACE_AFTER_LABEL:
                    if (Character.isDigit(ch))//move to next state
                    {
                        state = STATE.FEATURE_INDEX;
                    }
                    else if (Character.isWhitespace(ch))
                    {
                        if (ch == '\n' || ch == '\r')
                        {
                            tempVec.zeroOut();
                            sparceVecs.addDataPoint(new DataPoint(new SparseVector(maxLen, 0)));///no features again, add zero vec
                            state = STATE.NEWLINE;
                        }
                        else//normal whie space
                            position++;
                    }
                    else
                        throw new RuntimeException();
                    break;
                case FEATURE_INDEX:
                    if (Character.isDigit(ch))
                    {
                        processBuffer.append(ch);
                        position++;
                    }
                    else if(ch == ':')
                    {
                        indexProcessing = StringUtils.parseInt(processBuffer, 0, processBuffer.length())-1;
                        processBuffer.delete(0, processBuffer.length());
                        
                        
                        state = STATE.FEATURE_VALUE;
                        position++;
                    }
                    else
                        throw new RuntimeException();
                    break;
                case FEATURE_VALUE:
                    //we need to accept all the values that may be part of a float value
                    if (Character.isDigit(ch) || ch == '.' || ch == 'E' || ch == 'e' || ch == '-' || ch == '+')
                    {
                        processBuffer.append(ch);
                        position++;
                    }
                    else
                    {
                        double value = StringUtils.parseDouble(processBuffer, 0, processBuffer.length());
                        processBuffer.delete(0, processBuffer.length());
   
                        maxLen = Math.max(maxLen, indexProcessing+1);
                        tempVec.setLength(maxLen);
                        if (value != 0)
                            tempVec.set(indexProcessing, value);
                        
                        if (Character.isWhitespace(ch))
                            state = STATE.WHITESPACE_AFTER_FEATURE;
                        else
                            throw new RuntimeException();
                    }
                    
                    break;
                case WHITESPACE_AFTER_FEATURE:
                    if (Character.isDigit(ch))
                        state = STATE.FEATURE_INDEX;
                    else if (Character.isWhitespace(ch))
                    {
                        if (ch == '\n' || ch == '\r')
                        {
                            sparceVecs.addDataPoint(new DataPoint(tempVec.clone()));
                            tempVec.zeroOut();
                            state = STATE.NEWLINE;
                        }
                        else
                            position++;
                    }
                    break;
                case NEWLINE:
                    if (ch == '\n' || ch == '\r')
                        position++;
                    else
                    {
                        state = STATE.LABEL;
                    }
                    break;
            }
        }
        
        if (vectorLength > 0)
            if (maxLen > vectorLength)
                throw new RuntimeException("Length given was " + vectorLength + ", but observed length was " + maxLen);
            else
                maxLen = vectorLength;

        if(classification)
        {
            CategoricalData predicting = new CategoricalData(possibleCats.size());

            //Give categories a unique ordering to avoid loading issues based on the order categories are presented
            List<Double> allCatKeys = new DoubleList(possibleCats.keySet());
            Collections.sort(allCatKeys);
            for(int i = 0; i < allCatKeys.size(); i++)
                possibleCats.put(allCatKeys.get(i), i);
            //apply to target values now 
            
            IntList label_targets = IntList.view(labelVals.stream()
                    .mapToInt(possibleCats::get)
                    .toArray());

            sparceVecs.setNumNumeric(maxLen);
            sparceVecs.finishAdding();
            ClassificationDataSet cds = new ClassificationDataSet(sparceVecs, label_targets);

            if(store instanceof RowMajorStore)
                cds.applyTransform(new DenseSparceTransform(sparseRatio));

            return cds;
        }
        else//regression
        {
            sparceVecs.setNumNumeric(maxLen);
            sparceVecs.finishAdding();
            RegressionDataSet rds = new RegressionDataSet(sparceVecs, labelVals);
            rds.applyTransform(new DenseSparceTransform(sparseRatio));

            return rds;
        }
    }
505838
private Document loadValidating(File file) {
		try {
			return getDOMObject(file.getAbsolutePath(), true);
		} catch (SAXException e) {
			e.printStackTrace();
			System.out.println("Error parsing digital document from nitf file "
					+ file + ".");
		} catch (IOException e) {
			e.printStackTrace();
			System.out.println("Error parsing digital document from nitf file "
					+ file + ".");
		} catch (ParserConfigurationException e) {
			e.printStackTrace();
			System.out.println("Error parsing digital document from nitf file "
					+ file + ".");
		}
		return null;
	}
1104261
public static Word2VecModel fromBinFile(File file)
			throws IOException {
		return fromBinFile(file, ByteOrder.LITTLE_ENDIAN, ProfilingTimer.NONE);
	}
368341
private void load() throws IOException
   {
      if (PrivilegedFileHelper.exists(storage))
      {
         InputStream in = PrivilegedFileHelper.fileInputStream(storage);
         try
         {
            Properties props = new Properties();
            log.debug("loading namespace mappings...");
            props.load(in);

            // read mappings from properties
            Iterator<Object> iter = props.keySet().iterator();
            while (iter.hasNext())
            {
               String prefix = (String)iter.next();
               String uri = props.getProperty(prefix);
               log.debug(prefix + " -> " + uri);
               prefixToURI.put(prefix, uri);
               uriToPrefix.put(uri, prefix);
            }
            prefixCount = props.size();
            log.debug("namespace mappings loaded.");
         }
         finally
         {
            in.close();
         }
      }
   }
127729
static String readMapping(String root, String index) throws IOException {
		if (root == null) {
			return readMapping(index);
		}
		String mappingFile = root + "/" + index + "/_doc" + Defaults.JsonFileExtension;
		return readFileFromClasspath(mappingFile);
	}
677396
def load(self, filepath):
        """"""
        for attributeLines in oboTermParser(filepath):
            oboTerm = _attributeLinesToDict(attributeLines)
            if oboTerm['id'] not in self.oboTerms:
                self.oboTerms[oboTerm['id']] = oboTerm            
            else:
                oldOboTerm = self.oboTerms[oboTerm['id']]
                oldTermIsObsolete = _termIsObsolete(oldOboTerm)
                newTermIsObsolete = _termIsObsolete(oboTerm)
                if oldTermIsObsolete and not newTermIsObsolete:
                    self.oboTerms[oboTerm['id']] = oboTerm
                else:
                    #At least one of two terms with identical id must be obsolete
                    assert oldTermIsObsolete or newTermIsObsolete
594588
private static synchronized final HashMap<String, String> readExtensionMappings(String mappingFile) throws Exception {

        HashMap<String, String> extensionMappings = new HashMap<String, String>();

        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        Document doc = factory.newDocumentBuilder().parse(new File(mappingFile));
        Element root = doc.getDocumentElement();
        // "mime-mapping" elements are children of root
        NodeList mappingNodes = root.getChildNodes();
        for (int i = 0; i < mappingNodes.getLength(); i++) {
            Node mappingNode = mappingNodes.item(i);
            // check it's a mime-mapping element
            if (mappingNode.getNodeType() == Node.ELEMENT_NODE && mappingNode.getNodeName().equals("mime-mapping")) {
                // look for child elements "extension" and "mime-type" and get values from text nodes
                String extension = null;
                String mimeType = null;
                NodeList nl = mappingNode.getChildNodes();
                for (int j = 0; j < nl.getLength(); j++) {
                    Node n = nl.item(j);
                    if (n.getNodeType() == Node.ELEMENT_NODE) {
                        // assuming here that extension and mime-type nodes only have text content (no attrs etc)
                        if (n.getNodeName().equals("extension")) {
                            extension = n.getFirstChild().getNodeValue();
                        } else {
                            if (n.getNodeName().equals("mime-type")) {
                                mimeType = n.getFirstChild().getNodeValue();
                            }
                        }
                    }
                }
                // if we've got an extension and mime-type, and it's not in the list, add it.
                if (extension != null && mimeType != null) {
                    if (!extensionMappings.containsKey(mimeType)) {
                        extensionMappings.put(mimeType, extension);
                    } else {
                        logger.warn("Duplicate extension " + extension + " found for mime-type " + mimeType + " in " + mappingFile);
                    }
                } else {
                    logger.warn("Element mime-mapping is missing child elements mime-type and/or extension in " + mappingFile);
                }
            }
        }
        return extensionMappings;
    }
224935
public static TreeMap<String, CoreDictionary.Attribute> loadDictionary(String... pathArray) throws IOException
    {
        TreeMap<String, CoreDictionary.Attribute> map = new TreeMap<String, CoreDictionary.Attribute>();
        for (String path : pathArray)
        {
            File file = new File(path);
            String fileName = file.getName();
            int natureIndex = fileName.lastIndexOf(' ');
            Nature defaultNature = Nature.n;
            if (natureIndex > 0)
            {
                String natureString = fileName.substring(natureIndex + 1);
                path = file.getParent() + File.separator + fileName.substring(0, natureIndex);
                if (natureString.length() > 0 && !natureString.endsWith(".txt") && !natureString.endsWith(".csv"))
                {
                    defaultNature = Nature.create(natureString);
                }
            }
            BufferedReader br = new BufferedReader(new InputStreamReader(IOUtil.newInputStream(path), "UTF-8"));
            loadDictionary(br, map, path.endsWith(".csv"), defaultNature);
        }

        return map;
    }