This method obtain the quality scores array corresponding to the quality char sequence,
depending on the sequence's encoding, and calculate sequence's average quality and
maximum and minimum individual quality scores
431027
private void obtainQualityScoresFromQualityString() {
        int total = 0;
        this.maximumQuality = Integer.MIN_VALUE;
        this.minimumQuality = Integer.MAX_VALUE;
        // quality int array initialization
        qualityScoresArray = new int[this.quality.length()];

        // Transform each character in the quality String into a integer, depending on
        // the quality scale, and obtain the average, minimum and maximum values
        for (int i = 0; i < this.quality.length(); i++) {
            char c = this.quality.charAt(i);
            qualityScoresArray[i] = c - FastQ.SCALE_OFFSET[this.encoding];
            total += this.qualityScoresArray[i];

            this.maximumQuality = Math.max(this.qualityScoresArray[i], this.maximumQuality);
            this.minimumQuality = Math.min(this.qualityScoresArray[i], this.minimumQuality);
        }
        this.averageQuality = (double) total / this.quality.length();
    }
897048
def _calculateEncodingKey(comparator):
    
    encodingName = None
    for k, v in list(_encodings.items()):
        if v == comparator:
            encodingName = k
            break
    return encodingName
45657
private static Audit getCodeQualityAudit(JSONArray jsonArray, JSONArray global) {

        LOGGER.info("NFRR Audit Collector auditing CODE_QUALITY");
        Audit audit = new Audit();
        audit.setType(AuditType.CODE_QUALITY);
        Audit basicAudit;
        if ((basicAudit = doBasicAuditCheck(jsonArray, global, AuditType.CODE_QUALITY)) != null) {
            return basicAudit;
        }
        audit.setAuditStatus(AuditStatus.OK);
        audit.setDataStatus(DataStatus.OK);
        for (Object o : jsonArray) {
            Optional<Object> urlOptObj = Optional.ofNullable(((JSONObject) o).get(STR_URL));
            urlOptObj.ifPresent(urlObj -> audit.getUrl().add(urlOptObj.get().toString()));
            JSONArray auditJO = (JSONArray) ((JSONObject) o).get(STR_AUDITSTATUSES);
            auditJO.stream().map(aj -> audit.getAuditStatusCodes().add((String) aj));
            boolean ok = false;
            for (Object s : auditJO) {
                String status = (String) s;
                audit.getAuditStatusCodes().add(status);
                if (CodeQualityAuditStatus.CODE_QUALITY_AUDIT_OK.name().equalsIgnoreCase(status)) {
                    ok = true;
                    break;
                }
                if (CodeQualityAuditStatus.CODE_QUALITY_DETAIL_MISSING.name().equalsIgnoreCase(status)) {
                    audit.setAuditStatus(AuditStatus.NA);
                    audit.setDataStatus(DataStatus.NO_DATA);
                    return audit;
                }
            }
            if (!ok) {
                audit.setAuditStatus(AuditStatus.FAIL);
                return audit;
            }
        }
        return audit;
    }
697952
def retrieve_with_score(self, s):
        
        all_sim = []
        use_max_n = self.max_n is not None
        for comparison_string in self._get_comparison_strings(s):
            score = self.comparison_func(s, comparison_string)
            if score >= self.cutoff:
                all_sim.append((comparison_string, score))
                if use_max_n and len(all_sim) >= self.max_n:
                    return all_sim
        return all_sim
1331323
public boolean sequenceAndQualityLengthsMatch()
	{
		if (sequence == null && quality == null)
		{
			return true;
		}
		if ((sequence != null && quality == null) || (sequence == null && quality != null))
		{
			return false;
		}
		return sequence.length() == quality.length();
	}
846029
def ratings(str)
      all_valid_cjk(str).map do |enc|
        [
          enc,
          recode(enc, str).codepoints.map do |point|
            Analects::Models::Zi.codepoint_ranges.map.with_index do |range, idx|
              next 6 - idx if range.include?(point)
              0
            end.inject(:+)
          end.inject(:+)
        ]
      end.sort_by(&:last).reverse
    end
489248
def get_grade_system_mdata():
    """"""
    return {
        'numeric_score_increment': {
            'element_label': {
                'text': 'numeric score increment',
                'languageTypeId': str(DEFAULT_LANGUAGE_TYPE),
                'scriptTypeId': str(DEFAULT_SCRIPT_TYPE),
                'formatTypeId': str(DEFAULT_FORMAT_TYPE),
            },
            'instructions': {
                'text': 'enter a decimal value.',
                'languageTypeId': str(DEFAULT_LANGUAGE_TYPE),
                'scriptTypeId': str(DEFAULT_SCRIPT_TYPE),
                'formatTypeId': str(DEFAULT_FORMAT_TYPE),
            },
            'required': False,
            'read_only': False,
            'linked': False,
            'array': False,
            'default_decimal_values': [None],
            'syntax': 'DECIMAL',
            'decimal_scale': None,
            'minimum_decimal': None,
            'maximum_decimal': None,
            'decimal_set': [],
        },
        'lowest_numeric_score': {
            'element_label': {
                'text': 'lowest numeric score',
                'languageTypeId': str(DEFAULT_LANGUAGE_TYPE),
                'scriptTypeId': str(DEFAULT_SCRIPT_TYPE),
                'formatTypeId': str(DEFAULT_FORMAT_TYPE),
            },
            'instructions': {
                'text': 'enter a decimal value.',
                'languageTypeId': str(DEFAULT_LANGUAGE_TYPE),
                'scriptTypeId': str(DEFAULT_SCRIPT_TYPE),
                'formatTypeId': str(DEFAULT_FORMAT_TYPE),
            },
            'required': False,
            'read_only': False,
            'linked': False,
            'array': False,
            'default_decimal_values': [None],
            'syntax': 'DECIMAL',
            'decimal_scale': None,
            'minimum_decimal': None,
            'maximum_decimal': None,
            'decimal_set': [],
        },
        'based_on_grades': {
            'element_label': {
                'text': 'based on grades',
                'languageTypeId': str(DEFAULT_LANGUAGE_TYPE),
                'scriptTypeId': str(DEFAULT_SCRIPT_TYPE),
                'formatTypeId': str(DEFAULT_FORMAT_TYPE),
            },
            'instructions': {
                'text': 'enter either true or false.',
                'languageTypeId': str(DEFAULT_LANGUAGE_TYPE),
                'scriptTypeId': str(DEFAULT_SCRIPT_TYPE),
                'formatTypeId': str(DEFAULT_FORMAT_TYPE),
            },
            'required': False,
            'read_only': False,
            'linked': False,
            'array': False,
            'default_boolean_values': [None],
            'syntax': 'BOOLEAN',
        },
        'highest_numeric_score': {
            'element_label': {
                'text': 'highest numeric score',
                'languageTypeId': str(DEFAULT_LANGUAGE_TYPE),
                'scriptTypeId': str(DEFAULT_SCRIPT_TYPE),
                'formatTypeId': str(DEFAULT_FORMAT_TYPE),
            },
            'instructions': {
                'text': 'enter a decimal value.',
                'languageTypeId': str(DEFAULT_LANGUAGE_TYPE),
                'scriptTypeId': str(DEFAULT_SCRIPT_TYPE),
                'formatTypeId': str(DEFAULT_FORMAT_TYPE),
            },
            'required': False,
            'read_only': False,
            'linked': False,
            'array': False,
            'default_decimal_values': [None],
            'syntax': 'DECIMAL',
            'decimal_scale': None,
            'minimum_decimal': None,
            'maximum_decimal': None,
            'decimal_set': [],
        },
    }
235344
def get_sequence_rule_mdata():
    """"""
    return {
        'next_assessment_part': {
            'element_label': {
                'text': 'next assessment part',
                'languageTypeId': str(DEFAULT_LANGUAGE_TYPE),
                'scriptTypeId': str(DEFAULT_SCRIPT_TYPE),
                'formatTypeId': str(DEFAULT_FORMAT_TYPE),
            },
            'instructions': {
                'text': 'accepts an osid.id.Id object',
                'languageTypeId': str(DEFAULT_LANGUAGE_TYPE),
                'scriptTypeId': str(DEFAULT_SCRIPT_TYPE),
                'formatTypeId': str(DEFAULT_FORMAT_TYPE),
            },
            'required': False,
            'read_only': False,
            'linked': False,
            'array': False,
            'default_id_values': [''],
            'syntax': 'ID',
            'id_set': [],
        },
        'cumulative': {
            'element_label': {
                'text': 'cumulative',
                'languageTypeId': str(DEFAULT_LANGUAGE_TYPE),
                'scriptTypeId': str(DEFAULT_SCRIPT_TYPE),
                'formatTypeId': str(DEFAULT_FORMAT_TYPE),
            },
            'instructions': {
                'text': 'enter either true or false.',
                'languageTypeId': str(DEFAULT_LANGUAGE_TYPE),
                'scriptTypeId': str(DEFAULT_SCRIPT_TYPE),
                'formatTypeId': str(DEFAULT_FORMAT_TYPE),
            },
            'required': False,
            'read_only': False,
            'linked': False,
            'array': False,
            'default_boolean_values': [None],
            'syntax': 'BOOLEAN',
        },
        'assessment_part': {
            'element_label': {
                'text': 'assessment part',
                'languageTypeId': str(DEFAULT_LANGUAGE_TYPE),
                'scriptTypeId': str(DEFAULT_SCRIPT_TYPE),
                'formatTypeId': str(DEFAULT_FORMAT_TYPE),
            },
            'instructions': {
                'text': 'accepts an osid.id.Id object',
                'languageTypeId': str(DEFAULT_LANGUAGE_TYPE),
                'scriptTypeId': str(DEFAULT_SCRIPT_TYPE),
                'formatTypeId': str(DEFAULT_FORMAT_TYPE),
            },
            'required': False,
            'read_only': False,
            'linked': False,
            'array': False,
            'default_id_values': [''],
            'syntax': 'ID',
            'id_set': [],
        },
        'minimum_score': {
            'element_label': {
                'text': 'minimum score',
                'languageTypeId': str(DEFAULT_LANGUAGE_TYPE),
                'scriptTypeId': str(DEFAULT_SCRIPT_TYPE),
                'formatTypeId': str(DEFAULT_FORMAT_TYPE),
            },
            'instructions': {
                'text': 'enter a cardinal value',
                'languageTypeId': str(DEFAULT_LANGUAGE_TYPE),
                'scriptTypeId': str(DEFAULT_SCRIPT_TYPE),
                'formatTypeId': str(DEFAULT_FORMAT_TYPE),
            },
            'required': False,
            'read_only': False,
            'linked': False,
            'array': False,
            'default_cardinal_values': [None],
            'syntax': 'CARDINAL',
            'minimum_cardinal': None,
            'maximum_cardinal': None,
            'cardinal_set': []
        },
        'maximum_score': {
            'element_label': {
                'text': 'maximum score',
                'languageTypeId': str(DEFAULT_LANGUAGE_TYPE),
                'scriptTypeId': str(DEFAULT_SCRIPT_TYPE),
                'formatTypeId': str(DEFAULT_FORMAT_TYPE),
            },
            'instructions': {
                'text': 'enter a cardinal value',
                'languageTypeId': str(DEFAULT_LANGUAGE_TYPE),
                'scriptTypeId': str(DEFAULT_SCRIPT_TYPE),
                'formatTypeId': str(DEFAULT_FORMAT_TYPE),
            },
            'required': False,
            'read_only': False,
            'linked': False,
            'array': False,
            'default_cardinal_values': [None],
            'syntax': 'CARDINAL',
            'minimum_cardinal': None,
            'maximum_cardinal': None,
            'cardinal_set': []
        },
    }
1066330
private static Map<Integer, Double> initializeScores(Map<Integer, Integer> alignment,
			Map<Integer, Double> scores, int k) {
		if(scores == null) {
			scores = new HashMap<Integer, Double>(alignment.size());
		} else {
			scores.clear();
		}
		Map<Integer,Integer> alignK = AlignmentTools.applyAlignment(alignment, k);

		// calculate input range
		int maxPre = Integer.MIN_VALUE;
		int minPre = Integer.MAX_VALUE;
		for(Integer pre : alignment.keySet()) {
			if(pre>maxPre) maxPre = pre;
			if(pre<minPre) minPre = pre;
		}

		for(Integer pre : alignment.keySet()) {
			Integer image = alignK.get(pre);

			// Use the absolute error score, |x - f^k(x)|
			double score = scoreAbsError(pre,image,minPre,maxPre);
			scores.put(pre, score);
		}
		return scores;
	}
257189
void score(final List<Integer> attributes,
               List<Double> retval)
    {
        Map <Integer,Integer >   encoder = precomputation_id_encoder;
        // arma.vec hidden_layer = arma.zeros<arma.vec>(hidden_layer_size);
        Matrix hidden_layer = Matrix.zero(hidden_layer_size, 1);

        for (int i = 0, off = 0; i < attributes.size(); ++i, off += embedding_size)
        {
            int aid = attributes.get(i);
            int fid = aid * nr_feature_types + i;
            Integer rep = encoder.get(fid);
            if (rep != null)
            {
                hidden_layer.plusEquals(saved.col(rep));
            }
            else
            {
                // 使用向量而不是特征本身
                // W1[0:hidden_layer, off:off+embedding_size] * E[fid:]'
                hidden_layer.plusEquals(W1.block(0, off, hidden_layer_size, embedding_size).times(E.col(aid)));
            }
        }

        hidden_layer.plusEquals(b1);    // 加上偏置

        Matrix output = W2.times(new Matrix (hidden_layer.cube())); // 立方激活函数
//        retval.resize(nr_classes, 0.);
        retval.clear();
        for (int i = 0; i < nr_classes; ++i)
        {
            retval.add(output.get(i, 0));
        }
    }
1303331
def qvalue(charset)
      m = matches(charset)
      if m.empty?
        charset == 'iso-8859-1' ? 1 : 0
      else
        normalize_qvalue(@qvalues[m.first])
      end
    end
1075615
def compute_quality_score(self, quality):
        """"""
        score = 0
        UNIT = 2
        if 'frequency' in quality:
            # TODO: should be related to frequency.
            if quality['update_in'] < 0:
                score += UNIT
            else:
                score -= UNIT
        if 'tags_count' in quality:
            if quality['tags_count'] > 3:
                score += UNIT
        if 'description_length' in quality:
            if quality['description_length'] > 100:
                score += UNIT
        if 'has_resources' in quality:
            if quality['has_only_closed_or_no_formats']:
                score -= UNIT
            else:
                score += UNIT
            if quality['has_unavailable_resources']:
                score -= UNIT
            else:
                score += UNIT
        if 'discussions' in quality:
            if quality['has_untreated_discussions']:
                score -= UNIT
            else:
                score += UNIT
        if score < 0:
            return 0
        return score
430499
private ColumnSpec[] parseColumnSpecs() {
        List encodedColumnSpecs = split(source, 0);
        int columnCount = encodedColumnSpecs.size();
        ColumnSpec[] columnSpecs = new ColumnSpec[columnCount];
        for (int i = 0; i < columnCount; i++) {
            String encodedSpec = (String) encodedColumnSpecs.get(i);
            columnSpecs[i] = ColumnSpec.decodeExpanded(encodedSpec);
        }
        return columnSpecs;
    }
217948
def GetEncoding(self):
        ''''''
        if self.encoding:
            vals = string.split(self.encoding, ',')
            if len(vals) > 2:
                try:
                    return charset_table[int(vals[2])]
                except KeyError:
                    pass
        return None
799979
def parse_qc(self, qc_file):
        
        import pandas as pd
        series = pd.Series()
        try:
            with open(qc_file) as handle:
                line = handle.readlines()[0].strip().split("\t")  # list of strings per line
            series["NSC"] = line[-3]
            series["RSC"] = line[-2]
            series["qualityTag"] = line[-1]
        except:
            pass
        return series
468725
private Double fetchQualityValue(Iterable<CodeQuality> qualityIterable, String param) {
    Double paramValue = null;
    Iterator<CodeQuality> qualityIterator = qualityIterable.iterator();

    if (!qualityIterator.hasNext()) {
      return paramValue;
    }

    CodeQuality codeQuality = qualityIterator.next();
    for (CodeQualityMetric codeQualityMetric : codeQuality.getMetrics()) {
      if (codeQualityMetric.getName().equals(param)) {
        paramValue = Double.valueOf(codeQualityMetric.getValue());
        break;
      }
    }

    return paramValue;
  }
452704
def _prepare_sort_by_score(self, values, sort_options):
        
        # create the keys
        base_tmp_key, tmp_keys = self._zset_to_keys(
                                    key=self._sort_by_sortedset['by'],
                                    values=values,
                                    )
        # ask to sort on our new keys
        sort_options['by'] = '%s:*' % base_tmp_key

        # retrieve original sort parameters
        for key in ('desc', 'alpha', 'get', 'store'):
            if key in self._sort_by_sortedset:
                sort_options[key] = self._sort_by_sortedset[key]

        # if we want to get the score with values/values_list
        if sort_options.get('get'):
            try:
                pos = sort_options['get'].index(SORTED_SCORE)
            except:
                pass
            else:
                sort_options['get'][pos] = '%s:*' % base_tmp_key

        return base_tmp_key, tmp_keys