Skip to content

Commit 3b4535e

Browse files
committed
🚧 Improved name parsing logic (WIP)
1 parent b85c65d commit 3b4535e

File tree

3 files changed

+14
-14
lines changed

3 files changed

+14
-14
lines changed

src/lice_comb/impl/id_detection.clj

+3-3
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@
371371
:fn (constantly ["Zlib" :high])}
372372
])))
373373

374-
(defn- parse-id
374+
(defn- detect-id
375375
"If a match occured for the given regex element when tested against string s,
376376
returns a map containing the following keys:
377377
* :id The SPDX license or exception identifier that was determined
@@ -395,7 +395,7 @@
395395
:start (:start match)}
396396
(when (seq confidence-explanations) {:confidence-explanations confidence-explanations})))))
397397

398-
(defn parse-ids
398+
(defn detect-ids
399399
"Returns a sequence (NOT A SET!) of maps where each key is a SPDX license or
400400
exception identifier (a String) that was found in s, and the value is a
401401
sequence containing a single map describing how the identifier was determined.
@@ -411,7 +411,7 @@
411411
Results are in the order in which they appear in the string, and the function
412412
returns nil if there were no matches."
413413
[s]
414-
(when-let [matches (seq (filter identity (e/pmap* (partial parse-id s) @license-name-matching-d)))]
414+
(when-let [matches (seq (filter identity (e/pmap* (partial detect-id s) @license-name-matching-d)))]
415415
(some->> matches
416416
(med/distinct-by :id) ;####TODO: THINK ABOUT MERGING INSTEAD OF DROPPING
417417
(sort-by :start)

src/lice_comb/impl/parsing.clj

+2-2
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,8 @@
207207
(when-let [ids (parse-uri s)]
208208
(map #(hash-map (key %) (val %)) ids))
209209

210-
; 5. Attempt to parse ids from the name
211-
(lciid/parse-ids s)
210+
; 5. Attempt to detect ids in the string
211+
(lciid/detect-ids s)
212212

213213
; 6. No clue, so return a single info map, but with a made up "UNIDENTIFIED-" value (NOT A LICENSEREF!) instead of an SPDX license or exception identifier
214214
(let [id (str "UNIDENTIFIED-" s)]

test/lice_comb/impl/id_parsing_test.clj test/lice_comb/impl/id_detection_test.clj

+9-9
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@
1616
; SPDX-License-Identifier: Apache-2.0
1717
;
1818

19-
(ns lice-comb.impl.id-parsing-test
20-
(:require [clojure.test :refer [deftest testing is use-fixtures]]
21-
[clojure.set :as set]
22-
[rencg.api :as rencg]
23-
[lice-comb.impl.utils :as lcu]
24-
[lice-comb.test-boilerplate :refer [fixture testing-with-data]]
25-
[lice-comb.impl.id-parsing :refer [init! version-re only-or-later-re agpl-re lgpl-re gpl-re gnu-re parse-ids]]))
19+
(ns lice-comb.impl.id-detection-test
20+
(:require [clojure.test :refer [deftest testing is use-fixtures]]
21+
[clojure.set :as set]
22+
[rencg.api :as rencg]
23+
[lice-comb.impl.utils :as lcu]
24+
[lice-comb.test-boilerplate :refer [fixture testing-with-data]]
25+
[lice-comb.impl.id-detection :refer [init! version-re only-or-later-re agpl-re lgpl-re gpl-re gnu-re detect-ids]]))
2626

2727
(use-fixtures :once fixture)
2828

@@ -248,5 +248,5 @@
248248
(is (every? not-nil? (map (partial test-regex gnu-re) gnu-licenses)))))
249249

250250
(deftest match-regexes-tests
251-
(testing-with-data "GNU Family Regexes - correct identifier results" #(mapcat keys (parse-ids %)) gnu-licenses-and-ids)
252-
(testing-with-data "CC Family Regexes - correct identifier results" #(mapcat keys (parse-ids %)) cc-by-licenses-and-ids))
251+
(testing-with-data "GNU Family Regexes - correct identifier results" #(mapcat keys (detect-ids %)) gnu-licenses-and-ids)
252+
(testing-with-data "CC Family Regexes - correct identifier results" #(mapcat keys (detect-ids %)) cc-by-licenses-and-ids))

0 commit comments

Comments
 (0)