Search is not available for this dataset
text stringlengths 75 104k |
|---|
def quadratic_weighted_kappa(rater_a, rater_b, min_rating=None, max_rating=None):
"""
Calculates kappa correlation between rater_a and rater_b.
Kappa measures how well 2 quantities vary together.
rater_a is a list of rater a scores
rater_b is a list of rater b scores
min_rating is an optional ar... |
def confusion_matrix(rater_a, rater_b, min_rating=None, max_rating=None):
"""
Generates a confusion matrix between rater_a and rater_b
A confusion matrix shows how often 2 values agree and disagree
See quadratic_weighted_kappa for argument descriptions
"""
assert(len(rater_a) == len(rater_b))
... |
def histogram(ratings, min_rating=None, max_rating=None):
"""
Generates a frequency count of each rating on the scale
ratings is a list of scores
Returns a list of frequencies
"""
ratings = [int(r) for r in ratings]
if min_rating is None:
min_rating = min(ratings)
if max_rating i... |
def get_wordnet_syns(word):
"""
Utilize wordnet (installed with nltk) to get synonyms for words
word is the input word
returns a list of unique synonyms
"""
synonyms = []
regex = r"_"
pat = re.compile(regex)
synset = nltk.wordnet.wordnet.synsets(word)
for ss in synset:
fo... |
def get_separator_words(toks1):
"""
Finds the words that separate a list of tokens from a background corpus
Basically this generates a list of informative/interesting words in a set
toks1 is a list of words
Returns a list of separator words
"""
tab_toks1 = nltk.FreqDist(word.lower() for word... |
def encode_plus(s):
"""
Literally encodes the plus sign
input is a string
returns the string with plus signs encoded
"""
regex = r"\+"
pat = re.compile(regex)
return pat.sub("%2B", s) |
def getMedian(numericValues):
"""
Gets the median of a list of values
Returns a float/int
"""
theValues = sorted(numericValues)
if len(theValues) % 2 == 1:
return theValues[(len(theValues) + 1) / 2 - 1]
else:
lower = theValues[len(theValues) / 2 - 1]
upper = theValue... |
def initialize_dictionaries(self, e_set, max_feats2 = 200):
"""
Initializes dictionaries from an essay set object
Dictionaries must be initialized prior to using this to extract features
e_set is an input essay set
returns a confirmation of initialization
"""
if(h... |
def get_good_pos_ngrams(self):
"""
Gets a set of gramatically correct part of speech sequences from an input file called essaycorpus.txt
Returns the set and caches the file
"""
if(os.path.isfile(NGRAM_PATH)):
good_pos_ngrams = pickle.load(open(NGRAM_PATH, 'rb'))
... |
def _get_grammar_errors(self,pos,text,tokens):
"""
Internal function to get the number of grammar errors in given text
pos - part of speech tagged text (list)
text - normal text (list)
tokens - list of lists of tokenized text
"""
word_counts = [max(len(t),1) for t... |
def gen_length_feats(self, e_set):
"""
Generates length based features from an essay set
Generally an internal function called by gen_feats
Returns an array of length features
e_set - EssaySet object
"""
text = e_set._text
lengths = [len(e) for e in text]
... |
def gen_bag_feats(self, e_set):
"""
Generates bag of words features from an input essay set and trained FeatureExtractor
Generally called by gen_feats
Returns an array of features
e_set - EssaySet object
"""
if(hasattr(self, '_stem_dict')):
sfeats = se... |
def gen_feats(self, e_set):
"""
Generates bag of words, length, and prompt features from an essay set object
returns an array of features
e_set - EssaySet object
"""
bag_feats = self.gen_bag_feats(e_set)
length_feats = self.gen_length_feats(e_set)
prompt_f... |
def gen_prompt_feats(self, e_set):
"""
Generates prompt based features from an essay set object and internal prompt variable.
Generally called internally by gen_feats
Returns an array of prompt features
e_set - EssaySet object
"""
prompt_toks = nltk.word_tokenize(... |
def gen_feedback(self, e_set, features=None):
"""
Generate feedback for a given set of essays
e_set - EssaySet object
features - optionally, pass in a matrix of features extracted from e_set using FeatureExtractor
in order to get off topic feedback.
Returns a list of list... |
def add_essay(self, essay_text, essay_score, essay_generated=0):
"""
Add new (essay_text,essay_score) pair to the essay set.
essay_text must be a string.
essay_score must be an int.
essay_generated should not be changed by the user.
Returns a confirmation that essay was a... |
def update_prompt(self, prompt_text):
"""
Update the default prompt string, which is "".
prompt_text should be a string.
Returns the prompt as a confirmation.
"""
if(isinstance(prompt_text, basestring)):
self._prompt = util_functions.sub_chars(prompt_text)
... |
def generate_additional_essays(self, e_text, e_score, dictionary=None, max_syns=3):
"""
Substitute synonyms to generate extra essays from existing ones.
This is done to increase the amount of training data.
Should only be used with lowest scoring essays.
e_text is the text of the... |
def create(text,score,prompt_string, dump_data=False):
"""
Creates a machine learning model from input text, associated scores, a prompt, and a path to the model
TODO: Remove model path argument, it is needed for now to support legacy code
text - A list of strings containing the text of the essays
s... |
def create_generic(numeric_values, textual_values, target, algorithm = util_functions.AlgorithmTypes.regression):
"""
Creates a model from a generic list numeric values and text values
numeric_values - A list of lists that are the predictors
textual_values - A list of lists that are the predictors
(... |
def create_essay_set(text, score, prompt_string, generate_additional=True):
"""
Creates an essay set from given data.
Text should be a list of strings corresponding to essay text.
Score should be a list of scores where score[n] corresponds to text[n]
Prompt string is just a string containing the ess... |
def get_cv_error(clf,feats,scores):
"""
Gets cross validated error for a given classifier, set of features, and scores
clf - classifier
feats - features to feed into the classified and cross validate over
scores - scores associated with the features -- feature row 1 associates with score 1, etc.
... |
def get_algorithms(algorithm):
"""
Gets two classifiers for each type of algorithm, and returns them. First for predicting, second for cv error.
type - one of util_functions.AlgorithmTypes
"""
if algorithm == util_functions.AlgorithmTypes.classification:
clf = sklearn.ensemble.GradientBoost... |
def extract_features_and_generate_model_predictors(predictor_set, algorithm=util_functions.AlgorithmTypes.regression):
"""
Extracts features and generates predictors based on a given predictor set
predictor_set - a PredictorSet object that has been initialized with data
type - one of util_functions.Algo... |
def extract_features_and_generate_model(essays, algorithm=util_functions.AlgorithmTypes.regression):
"""
Feed in an essay set to get feature vector and classifier
essays must be an essay set object
additional array is an optional argument that can specify
a numpy array of values to add in
return... |
def dump_model_to_file(prompt_string, feature_ext, classifier, text, score, model_path):
"""
Writes out a model to a file.
prompt string is a string containing the prompt
feature_ext is a trained FeatureExtractor object
classifier is a trained classifier
model_path is the path of write out the m... |
def create_essay_set_and_dump_model(text,score,prompt,model_path,additional_array=None):
"""
Function that creates essay set, extracts features, and writes out model
See above functions for argument descriptions
"""
essay_set=create_essay_set(text,score,prompt)
feature_ext,clf=extract_features_a... |
def initialize_dictionaries(self, p_set):
"""
Initialize dictionaries with the textual inputs in the PredictorSet object
p_set - PredictorSet object that has had data fed in
"""
success = False
if not (hasattr(p_set, '_type')):
error_message = "needs to be an ... |
def gen_feats(self, p_set):
"""
Generates features based on an iput p_set
p_set - PredictorSet
"""
if self._initialized!=True:
error_message = "Dictionaries have not been initialized."
log.exception(error_message)
raise util_functions.InputErro... |
def t_text(self, t):
r':\s*<text>'
t.lexer.text_start = t.lexer.lexpos - len('<text>')
t.lexer.begin('text') |
def t_text_end(self, t):
r'</text>\s*'
t.type = 'TEXT'
t.value = t.lexer.lexdata[
t.lexer.text_start:t.lexer.lexpos]
t.lexer.lineno += t.value.count('\n')
t.value = t.value.strip()
t.lexer.begin('INITIAL')
return t |
def t_KEYWORD_AS_TAG(self, t):
r'[a-zA-Z]+'
t.type = self.reserved.get(t.value, 'UNKNOWN_TAG')
t.value = t.value.strip()
return t |
def t_LINE_OR_KEYWORD_VALUE(self, t):
r':.+'
t.value = t.value[1:].strip()
if t.value in self.reserved.keys():
t.type = self.reserved[t.value]
else:
t.type = 'LINE'
return t |
def tv_to_rdf(infile_name, outfile_name):
"""
Convert a SPDX file from tag/value format to RDF format.
Return True on sucess, False otherwise.
"""
parser = Parser(Builder(), StandardLogger())
parser.build()
with open(infile_name) as infile:
data = infile.read()
document, erro... |
def order_error(self, first_tag, second_tag, line):
"""Reports an OrderError. Error message will state that
first_tag came before second_tag.
"""
self.error = True
msg = ERROR_MESSAGES['A_BEFORE_B'].format(first_tag, second_tag, line)
self.logger.log(msg) |
def p_lic_xref_1(self, p):
"""lic_xref : LICS_CRS_REF LINE"""
try:
if six.PY2:
value = p[2].decode(encoding='utf-8')
else:
value = p[2]
self.builder.add_lic_xref(self.document, value)
except OrderError:
self.order_er... |
def p_lic_comment_1(self, p):
"""lic_comment : LICS_COMMENT TEXT"""
try:
if six.PY2:
value = p[2].decode(encoding='utf-8')
else:
value = p[2]
self.builder.set_lic_comment(self.document, value)
except OrderError:
self... |
def p_extr_lic_name_1(self, p):
"""extr_lic_name : LICS_NAME extr_lic_name_value"""
try:
self.builder.set_lic_name(self.document, p[2])
except OrderError:
self.order_error('LicenseName', 'LicenseID', p.lineno(1))
except CardinalityError:
self.more_than... |
def p_extr_lic_name_value_1(self, p):
"""extr_lic_name_value : LINE"""
if six.PY2:
p[0] = p[1].decode(encoding='utf-8')
else:
p[0] = p[1] |
def p_extr_lic_text_1(self, p):
"""extr_lic_text : LICS_TEXT TEXT"""
try:
if six.PY2:
value = p[2].decode(encoding='utf-8')
else:
value = p[2]
self.builder.set_lic_text(self.document, value)
except OrderError:
self.o... |
def p_extr_lic_id_1(self, p):
"""extr_lic_id : LICS_ID LINE"""
try:
if six.PY2:
value = p[2].decode(encoding='utf-8')
else:
value = p[2]
self.builder.set_lic_id(self.document, value)
except SPDXValueError:
self.error... |
def p_prj_uri_art_3(self, p):
"""prj_uri_art : ART_PRJ_URI error"""
self.error = True
msg = ERROR_MESSAGES['ART_PRJ_URI_VALUE'].format(p.lineno(1))
self.logger.log(msg) |
def p_prj_home_art_1(self, p):
"""prj_home_art : ART_PRJ_HOME LINE"""
try:
self.builder.set_file_atrificat_of_project(self.document, 'home', p[2])
except OrderError:
self.order_error('ArtificatOfProjectHomePage', 'FileName', p.lineno(1)) |
def p_prj_home_art_2(self, p):
"""prj_home_art : ART_PRJ_HOME UN_KNOWN"""
try:
self.builder.set_file_atrificat_of_project(self.document,
'home', utils.UnKnown())
except OrderError:
self.order_error('ArtifactOfProjectName', 'FileName', p.lineno(1)) |
def p_prj_name_art_1(self, p):
"""prj_name_art : ART_PRJ_NAME LINE"""
try:
if six.PY2:
value = p[2].decode(encoding='utf-8')
else:
value = p[2]
self.builder.set_file_atrificat_of_project(self.document, 'name', value)
except Orde... |
def p_file_dep_1(self, p):
"""file_dep : FILE_DEP LINE"""
try:
if six.PY2:
value = p[2].decode(encoding='utf-8')
else:
value = p[2]
self.builder.add_file_dep(self.document, value)
except OrderError:
self.order_error(... |
def p_file_contrib_1(self, p):
"""file_contrib : FILE_CONTRIB LINE"""
try:
if six.PY2:
value = p[2].decode(encoding='utf-8')
else:
value = p[2]
self.builder.add_file_contribution(self.document, value)
except OrderError:
... |
def p_file_notice_1(self, p):
"""file_notice : FILE_NOTICE TEXT"""
try:
if six.PY2:
value = p[2].decode(encoding='utf-8')
else:
value = p[2]
self.builder.set_file_notice(self.document, value)
except OrderError:
self.... |
def p_file_cr_text_1(self, p):
"""file_cr_text : FILE_CR_TEXT file_cr_value"""
try:
self.builder.set_file_copyright(self.document, p[2])
except OrderError:
self.order_error('FileCopyrightText', 'FileName', p.lineno(1))
except CardinalityError:
self.mor... |
def p_file_cr_value_1(self, p):
"""file_cr_value : TEXT"""
if six.PY2:
p[0] = p[1].decode(encoding='utf-8')
else:
p[0] = p[1] |
def p_file_lics_comment_1(self, p):
"""file_lics_comment : FILE_LICS_COMMENT TEXT"""
try:
if six.PY2:
value = p[2].decode(encoding='utf-8')
else:
value = p[2]
self.builder.set_file_license_comment(self.document, value)
except Or... |
def p_file_lics_info_1(self, p):
"""file_lics_info : FILE_LICS_INFO file_lic_info_value"""
try:
self.builder.set_file_license_in_file(self.document, p[2])
except OrderError:
self.order_error('LicenseInfoInFile', 'FileName', p.lineno(1))
except SPDXValueError:
... |
def p_conc_license_3(self, p):
"""conc_license : LINE"""
if six.PY2:
value = p[1].decode(encoding='utf-8')
else:
value = p[1]
ref_re = re.compile('LicenseRef-.+', re.UNICODE)
if (p[1] in config.LICENSE_MAP.keys()) or (ref_re.match(p[1]) is not None):
... |
def p_file_name_1(self, p):
"""file_name : FILE_NAME LINE"""
try:
if six.PY2:
value = p[2].decode(encoding='utf-8')
else:
value = p[2]
self.builder.set_file_name(self.document, value)
except OrderError:
self.order_er... |
def p_spdx_id(self, p):
"""spdx_id : SPDX_ID LINE"""
if six.PY2:
value = p[2].decode(encoding='utf-8')
else:
value = p[2]
if not self.builder.doc_spdx_id_set:
self.builder.set_doc_spdx_id(self.document, value)
else:
self.builder.set... |
def p_file_comment_1(self, p):
"""file_comment : FILE_COMMENT TEXT"""
try:
if six.PY2:
value = p[2].decode(encoding='utf-8')
else:
value = p[2]
self.builder.set_file_comment(self.document, value)
except OrderError:
s... |
def p_file_type_1(self, p):
"""file_type : FILE_TYPE file_type_value"""
try:
self.builder.set_file_type(self.document, p[2])
except OrderError:
self.order_error('FileType', 'FileName', p.lineno(1))
except CardinalityError:
self.more_than_one_error('Fil... |
def p_file_chksum_1(self, p):
"""file_chksum : FILE_CHKSUM CHKSUM"""
try:
if six.PY2:
value = p[2].decode(encoding='utf-8')
else:
value = p[2]
self.builder.set_file_chksum(self.document, value)
except OrderError:
sel... |
def p_file_conc_1(self, p):
"""file_conc : FILE_LICS_CONC conc_license"""
try:
self.builder.set_concluded_license(self.document, p[2])
except SPDXValueError:
self.error = True
msg = ERROR_MESSAGES['FILE_LICS_CONC_VALUE'].format(p.lineno(1))
self.lo... |
def p_file_type_value(self, p):
"""file_type_value : OTHER
| SOURCE
| ARCHIVE
| BINARY
"""
if six.PY2:
p[0] = p[1].decode(encoding='utf-8')
else:
p[0] = p[1] |
def p_pkg_desc_1(self, p):
"""pkg_desc : PKG_DESC TEXT"""
try:
if six.PY2:
value = p[2].decode(encoding='utf-8')
else:
value = p[2]
self.builder.set_pkg_desc(self.document, value)
except CardinalityError:
self.more_t... |
def p_pkg_summary_1(self, p):
"""pkg_summary : PKG_SUM TEXT"""
try:
if six.PY2:
value = p[2].decode(encoding='utf-8')
else:
value = p[2]
self.builder.set_pkg_summary(self.document, value)
except OrderError:
self.orde... |
def p_pkg_cr_text_1(self, p):
"""pkg_cr_text : PKG_CPY_TEXT pkg_cr_text_value"""
try:
self.builder.set_pkg_cr_text(self.document, p[2])
except OrderError:
self.order_error('PackageCopyrightText', 'PackageFileName', p.lineno(1))
except CardinalityError:
... |
def p_pkg_cr_text_value_1(self, p):
"""pkg_cr_text_value : TEXT"""
if six.PY2:
p[0] = p[1].decode(encoding='utf-8')
else:
p[0] = p[1] |
def p_pkg_lic_comment_1(self, p):
"""pkg_lic_comment : PKG_LICS_COMMENT TEXT"""
try:
if six.PY2:
value = p[2].decode(encoding='utf-8')
else:
value = p[2]
self.builder.set_pkg_license_comment(self.document, value)
except OrderErr... |
def p_pkg_lic_ff_1(self, p):
"""pkg_lic_ff : PKG_LICS_FFILE pkg_lic_ff_value"""
try:
self.builder.set_pkg_license_from_file(self.document, p[2])
except OrderError:
self.order_error('PackageLicenseInfoFromFiles', 'PackageName', p.lineno(1))
except SPDXValueError:
... |
def p_pkg_lic_ff_value_3(self, p):
"""pkg_lic_ff_value : LINE"""
if six.PY2:
value = p[1].decode(encoding='utf-8')
else:
value = p[1]
p[0] = document.License.from_identifier(value) |
def p_pkg_src_info_1(self, p):
"""pkg_src_info : PKG_SRC_INFO TEXT"""
try:
if six.PY2:
value = p[2].decode(encoding='utf-8')
else:
value = p[2]
self.builder.set_pkg_source_info(self.document, value)
except CardinalityError:
... |
def p_pkg_chksum_1(self, p):
"""pkg_chksum : PKG_CHKSUM CHKSUM"""
try:
if six.PY2:
value = p[2].decode(encoding='utf-8')
else:
value = p[2]
self.builder.set_pkg_chk_sum(self.document, value)
except OrderError:
self.o... |
def p_pkg_home_1(self, p):
"""pkg_home : PKG_HOME pkg_home_value"""
try:
self.builder.set_pkg_down_location(self.document, p[2])
except OrderError:
self.order_error('PackageHomePage', 'PackageName', p.lineno(1))
except CardinalityError:
self.more_than_... |
def p_pkg_home_2(self, p):
"""pkg_home : PKG_HOME error"""
self.error = True
msg = ERROR_MESSAGES['PKG_HOME_VALUE']
self.logger.log(msg) |
def p_pkg_home_value_1(self, p):
"""pkg_home_value : LINE"""
if six.PY2:
p[0] = p[1].decode(encoding='utf-8')
else:
p[0] = p[1] |
def p_pkg_down_value_1(self, p):
"""pkg_down_value : LINE """
if six.PY2:
p[0] = p[1].decode(encoding='utf-8')
else:
p[0] = p[1] |
def p_pkg_file_name(self, p):
"""pkg_file_name : PKG_FILE_NAME LINE"""
try:
if six.PY2:
value = p[2].decode(encoding='utf-8')
else:
value = p[2]
self.builder.set_pkg_file_name(self.document, value)
except OrderError:
... |
def p_package_version_1(self, p):
"""package_version : PKG_VERSION LINE"""
try:
if six.PY2:
value = p[2].decode(encoding='utf-8')
else:
value = p[2]
self.builder.set_pkg_vers(self.document, value)
except OrderError:
... |
def p_package_name(self, p):
"""package_name : PKG_NAME LINE"""
try:
if six.PY2:
value = p[2].decode(encoding='utf-8')
else:
value = p[2]
self.builder.create_package(self.document, value)
except CardinalityError:
sel... |
def p_review_date_1(self, p):
"""review_date : REVIEW_DATE DATE"""
try:
if six.PY2:
value = p[2].decode(encoding='utf-8')
else:
value = p[2]
self.builder.add_review_date(self.document, value)
except CardinalityError:
... |
def p_review_comment_1(self, p):
"""review_comment : REVIEW_COMMENT TEXT"""
try:
if six.PY2:
value = p[2].decode(encoding='utf-8')
else:
value = p[2]
self.builder.add_review_comment(self.document, value)
except CardinalityError:... |
def p_annotation_date_1(self, p):
"""annotation_date : ANNOTATION_DATE DATE"""
try:
if six.PY2:
value = p[2].decode(encoding='utf-8')
else:
value = p[2]
self.builder.add_annotation_date(self.document, value)
except CardinalityEr... |
def p_annotation_comment_1(self, p):
"""annotation_comment : ANNOTATION_COMMENT TEXT"""
try:
if six.PY2:
value = p[2].decode(encoding='utf-8')
else:
value = p[2]
self.builder.add_annotation_comment(self.document, value)
except C... |
def p_annotation_type_1(self, p):
"""annotation_type : ANNOTATION_TYPE LINE"""
try:
if six.PY2:
value = p[2].decode(encoding='utf-8')
else:
value = p[2]
self.builder.add_annotation_type(self.document, value)
except CardinalityEr... |
def p_annotation_spdx_id_1(self, p):
"""annotation_spdx_id : ANNOTATION_SPDX_ID LINE"""
try:
if six.PY2:
value = p[2].decode(encoding='utf-8')
else:
value = p[2]
self.builder.set_annotation_spdx_id(self.document, value)
except C... |
def p_doc_comment_1(self, p):
"""doc_comment : DOC_COMMENT TEXT"""
try:
if six.PY2:
value = p[2].decode(encoding='utf-8')
else:
value = p[2]
self.builder.set_doc_comment(self.document, value)
except CardinalityError:
... |
def p_doc_name_1(self, p):
"""doc_name : DOC_NAME LINE"""
try:
if six.PY2:
value = p[2].decode(encoding='utf-8')
else:
value = p[2]
self.builder.set_doc_name(self.document, value)
except CardinalityError:
self.more_t... |
def p_ext_doc_refs_1(self, p):
"""ext_doc_ref : EXT_DOC_REF DOC_REF_ID DOC_URI EXT_DOC_REF_CHKSUM"""
try:
if six.PY2:
doc_ref_id = p[2].decode(encoding='utf-8')
doc_uri = p[3].decode(encoding='utf-8')
ext_doc_chksum = p[4].decode(encoding='utf-... |
def p_spdx_version_1(self, p):
"""spdx_version : DOC_VERSION LINE"""
try:
if six.PY2:
value = p[2].decode(encoding='utf-8')
else:
value = p[2]
self.builder.set_doc_version(self.document, value)
except CardinalityError:
... |
def p_creator_comment_1(self, p):
"""creator_comment : CREATOR_COMMENT TEXT"""
try:
if six.PY2:
value = p[2].decode(encoding='utf-8')
else:
value = p[2]
self.builder.set_creation_comment(self.document, value)
except CardinalityE... |
def p_created_1(self, p):
"""created : CREATED DATE"""
try:
if six.PY2:
value = p[2].decode(encoding='utf-8')
else:
value = p[2]
self.builder.set_created_date(self.document, value)
except CardinalityError:
self.more_... |
def write_creation_info(creation_info, out):
"""
Write the creation info to out.
"""
out.write('# Creation Info\n\n')
# Write sorted creators
for creator in sorted(creation_info.creators):
write_value('Creator', creator, out)
# write created
write_value('Created', creation_info.... |
def write_review(review, out):
"""
Write the fields of a single review to out.
"""
out.write('# Review\n\n')
write_value('Reviewer', review.reviewer, out)
write_value('ReviewDate', review.review_date_iso_format, out)
if review.has_comment:
write_text_value('ReviewComment', review.com... |
def write_annotation(annotation, out):
"""
Write the fields of a single annotation to out.
"""
out.write('# Annotation\n\n')
write_value('Annotator', annotation.annotator, out)
write_value('AnnotationDate', annotation.annotation_date_iso_format, out)
if annotation.has_comment:
write_... |
def write_file(spdx_file, out):
"""
Write a file fields to out.
"""
out.write('# File\n\n')
write_value('FileName', spdx_file.name, out)
write_value('SPDXID', spdx_file.spdx_id, out)
if spdx_file.has_optional_field('type'):
write_file_type(spdx_file.type, out)
write_value('FileCh... |
def write_package(package, out):
"""
Write a package fields to out.
"""
out.write('# Package\n\n')
write_value('PackageName', package.name, out)
if package.has_optional_field('version'):
write_value('PackageVersion', package.version, out)
write_value('PackageDownloadLocation', packag... |
def write_extracted_licenses(lics, out):
"""
Write extracted licenses fields to out.
"""
write_value('LicenseID', lics.identifier, out)
if lics.full_name is not None:
write_value('LicenseName', lics.full_name, out)
if lics.comment is not None:
write_text_value('LicenseComment',... |
def write_document(document, out, validate=True):
"""
Write an SPDX tag value document.
- document - spdx.document instance.
- out - file like object that will be written to.
Optionally `validate` the document before writing and raise
InvalidDocumentError if document.validate returns False.
... |
def checksum_from_sha1(value):
"""
Return an spdx.checksum.Algorithm instance representing the SHA1
checksum or None if does not match CHECKSUM_RE.
"""
# More constrained regex at lexer level
CHECKSUM_RE = re.compile('SHA1:\s*([\S]+)', re.UNICODE)
match = CHECKSUM_RE.match(value)
if matc... |
def str_from_text(text):
"""
Return content of a free form text block as a string.
"""
REGEX = re.compile('<text>((.|\n)+)</text>', re.UNICODE)
match = REGEX.match(text)
if match:
return match.group(1)
else:
return None |
def set_doc_version(self, doc, value):
"""
Set the document version.
Raise SPDXValueError if malformed value, CardinalityError
if already defined
"""
if not self.doc_version_set:
self.doc_version_set = True
m = self.VERS_STR_REGEX.match(value)
... |
def set_doc_data_lics(self, doc, lics):
"""Sets the document data license.
Raises value error if malformed value, CardinalityError
if already defined.
"""
if not self.doc_data_lics_set:
self.doc_data_lics_set = True
if validations.validate_data_lics(lics):... |
def set_doc_name(self, doc, name):
"""Sets the document name.
Raises CardinalityError if already defined.
"""
if not self.doc_name_set:
doc.name = name
self.doc_name_set = True
return True
else:
raise CardinalityError('Document::Nam... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.