FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
ReportImportHelper.php
1 <?php
2 /*
3  * Copyright (C) 2015-2017, Siemens AG
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * version 2 as published by the Free Software Foundation.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License along
15  * with this program; if not, write to the Free Software Foundation, Inc.,
16  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  */
18 namespace Fossology\ReportImport;
19 
20 use EasyRdf_Graph;
21 
23 {
24  private static function getTokensFromlicenseExpression($licenseExpr) // TODO
25  {
26  return array_filter(explode(' ', str_replace(array("(",")"), " ", $licenseExpr)));
27  }
28 
29  public static function getShortnamesFromLicenseExpression($licenseExpr)
30  {
31  $licenseExprTokens = self::getTokensFromlicenseExpression($licenseExpr);
32  $shortnames = array();
33  $licenseRefPrefix = "LicenseRef-";
34  foreach($licenseExprTokens as $token){
35  if($token == "OR")
36  {
37  $shortnames[] = "Dual-license";
38  }
39  else if(substr($token, 0, strlen($licenseRefPrefix)) === $licenseRefPrefix)
40  {
41  $shortnames[] = urldecode(substr($token, strlen($licenseRefPrefix)));
42  }
43  else
44  {
45  $shortnames[] = urldecode($token);
46  }
47  }
48  return $shortnames;
49  }
50 
51  public static function stripPrefix($str)
52  {
53  $parts = explode('#', $str, 2);
54  if (sizeof($parts) === 2)
55  {
56  return $parts[1];
57  }
58  return "";
59  }
60 
61  public static function stripPrefixes($strs)
62  {
63  return array_map(array(__CLASS__, "stripPrefix"), $strs);
64  }
65 
66 }