|
236 | 236 | [s]
|
237 | 237 | (when-not (s/blank? s)
|
238 | 238 | (->> (s/split (s/trim s) #"(?i)\band[/-\\]+or\b")
|
239 |
| - (map-split-and-interpose #"(?i)(\band\b|\&)(?!\s+(distribution|all\s+rights\s+reserved))" :and) |
240 |
| - (map-split-and-interpose #"(?i)\bor\b(?!\s*(-?(any\s+)?later|(any\s+)?lator|(any\s+)?newer|lesser|library|\(?at\s+your\s+(option|discretion)\)?|([\"']?(Revised|Modified)[\"']?)))" :or) |
241 |
| - (map-split-and-interpose #"(?i)\b(with\b|w/)(?!\s+the\s+acknowledgment\s+clause\s+removed)" :with) |
| 239 | + (map-split-and-interpose #"(?i)(\band\b|\&)(?!\s+(distribution|all\s+rights\s+reserved))" |
| 240 | + :and) |
| 241 | + (map-split-and-interpose #"(?i)\bor\b(?!\s*(-?(greater|(any\s+)?later|(any\s+)?lator|(any\s+)?newer|lesser|library|\(?at\s+your\s+(option|discretion)\)?|([\"']?(Revised|Modified)[\"']?))))" |
| 242 | + :or) |
| 243 | + (map-split-and-interpose #"(?i)\b(with\b|w/)(?!\s+the\s+acknowledgment\s+clause\s+removed)" |
| 244 | + :with) |
242 | 245 | filter-blanks
|
243 | 246 | (map #(if (string? %) (s/trim %) %)))))
|
244 | 247 |
|
| 248 | +(defn- collapse-unlisted-exceptions |
| 249 | + "Collapses exception fragments with a LicenseRef on the right side (which is |
| 250 | + not valid in SPDX v2.3, returning a single LicenseRef for the entire fragment |
| 251 | + instead. |
| 252 | +
|
| 253 | + Note: this will need to change substantially as part of https://github.com/pmonks/lice-comb/issues/42" |
| 254 | + [l] |
| 255 | + (loop [f (take 3 l) |
| 256 | + r (rest l) |
| 257 | + result nil] |
| 258 | + (if (< (count f) 3) |
| 259 | + (concat result f) |
| 260 | + (let [left (first f) |
| 261 | + op (second f) |
| 262 | + right (second (rest f))] |
| 263 | + (if (and (= :with op) (lcis/unidentified? (first (keys right)))) |
| 264 | + (let [skip2 (rest (rest r)) |
| 265 | + left-name (first (:source (first (first (vals left))))) |
| 266 | + right-name (lcis/unidentified->name (first (keys right))) |
| 267 | + new-name (str left-name " with " right-name) |
| 268 | + new-id (lcis/name->unidentified new-name)] |
| 269 | + (recur (take 3 skip2) (rest skip2) |
| 270 | + (concat result (list {new-id (list {:id new-id :type :concluded :confidence :low :strategy :unidentified :source (list new-name)})})))) |
| 271 | + (recur (take 3 r) (rest r) |
| 272 | + (concat result (list left)))))))) |
| 273 | + |
245 | 274 | (def ^:private push conj) ; With lists-as-stacks conj == push
|
246 | 275 |
|
247 | 276 | (defn- calculate-confidence-for-expression
|
|
308 | 337 | (get @cursed-names-d name)
|
309 | 338 |
|
310 | 339 | ; 2. Construct an expressions-info map from the name
|
311 |
| - (some->> (split-on-operators name) |
312 |
| - (drop-while keyword?) |
313 |
| - (lc3/rdrop-while keyword?) |
314 |
| - (map #(if (keyword? %) % (string->ids-info %))) |
315 |
| - flatten |
316 |
| - seq |
317 |
| - build-expressions-info-map |
318 |
| - (lciu/mapfonk sexp/normalise))))))) |
| 340 | + (let [partial-result (some->> (split-on-operators name) |
| 341 | + (drop-while keyword?) |
| 342 | + (lc3/rdrop-while keyword?) |
| 343 | + (map #(if (keyword? %) % (string->ids-info %))) |
| 344 | + flatten |
| 345 | + collapse-unlisted-exceptions |
| 346 | + seq) |
| 347 | + ids-only (seq (mapcat keys (filter map? partial-result)))] |
| 348 | + ; Check whether all we have are unidentified LicenseRefs, and if so just return the entire thing as a single unidentified LicenseRef |
| 349 | + (if (every? lcis/unidentified? ids-only) |
| 350 | + (let [id (lcis/name->unidentified (s/trim name))] |
| 351 | + {id (list {:id id :type :concluded :confidence :low :strategy :unidentified :source (list)})}) |
| 352 | + (some->> partial-result |
| 353 | + build-expressions-info-map |
| 354 | + (lciu/mapfonk sexp/normalise))))))))) |
319 | 355 |
|
320 | 356 | (defn init!
|
321 | 357 | "Initialises this namespace upon first call (and does nothing on subsequent
|
|
0 commit comments