Skip to content

Commit

Permalink
[issue-547] rdf parser: use licenseID from extracted licensing info U…
Browse files Browse the repository at this point in the history
…RIRef if no licenseId node is provided

Signed-off-by: Meret Behrens <meret.behrens@tngtech.com>
  • Loading branch information
meretp committed Mar 30, 2023
1 parent bde2774 commit 09c1efa
Show file tree
Hide file tree
Showing 6 changed files with 4,225 additions and 11 deletions.
11 changes: 10 additions & 1 deletion src/spdx/parser/rdf/extracted_licensing_info_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,18 @@
from spdx.rdfschema.namespace import SPDX_NAMESPACE


def parse_extracted_licensing_info(extracted_licensing_info_node: URIRef, graph: Graph) -> ExtractedLicensingInfo:
def parse_extracted_licensing_info(
extracted_licensing_info_node: URIRef, graph: Graph, doc_namespace: str
) -> ExtractedLicensingInfo:
logger = Logger()
license_id = parse_literal(logger, graph, extracted_licensing_info_node, SPDX_NAMESPACE.licenseId)
if not license_id:
license_id = (
extracted_licensing_info_node.fragment
if extracted_licensing_info_node.startswith(f"{doc_namespace}#")
else extracted_licensing_info_node.toPython()
)

extracted_text = parse_literal(logger, graph, extracted_licensing_info_node, SPDX_NAMESPACE.extractedText)
comment = parse_literal(logger, graph, extracted_licensing_info_node, RDFS.comment)
license_name = parse_literal_or_no_assertion_or_none(
Expand Down
4 changes: 3 additions & 1 deletion src/spdx/parser/rdf/rdf_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ def translate_graph_to_document(graph: Graph) -> Document:
extracted_licensing_infos = []
for _, _, extracted_licensing_info_node in graph.triples((None, SPDX_NAMESPACE.hasExtractedLicensingInfo, None)):
try:
extracted_licensing_infos.append(parse_extracted_licensing_info(extracted_licensing_info_node, graph))
extracted_licensing_infos.append(
parse_extracted_licensing_info(extracted_licensing_info_node, graph, creation_info.document_namespace)
)
except SPDXParsingError as err:
logger.extend(err.get_messages())
parsed_fields["extracted_licensing_info"] = extracted_licensing_infos
Expand Down
Loading

0 comments on commit 09c1efa

Please sign in to comment.