com.metaeffekt.artifact.analysis.metascan.CopyrightScanSupport Maven / Gradle / Ivy
The newest version!
/*
* Copyright 2021-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.metaeffekt.artifact.analysis.metascan;
import com.metaeffekt.artifact.analysis.utils.StringStats;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
public class CopyrightScanSupport {
public CopyrightScanResult scanForCopyrights(StringStats text) {
final CopyrightScanResult copyrightScanResult = new CopyrightScanResult();
// phase 1 - seed
Set seeds = new HashSet<>();
seed(text, seeds, "copyright");
seed(text, seeds, "Copyright");
seed(text, seeds, "GmbH");
seed(text, seeds, "Ltd");
seed(text, seeds, "Inc");
seed(text, seeds, "inc");
seed(text, seeds, "(c)");
seed(text, seeds, "(C)");
seedRegexp(text, seeds, ".*?@.*?\\.com");
return copyrightScanResult;
}
private void seed(StringStats text, Set seeds, String seed) {
final int[] seedIndex = text.allMatches(StringStats.normalize(seed, true));
for (int i : seedIndex) {
seeds.add(new CopyrightSeed(seed, i));
}
}
private void seedRegexp(StringStats text, Set seeds, String seedRegexp) {
List seedIndexes = text.matchRegexp(StringStats.normalize(seedRegexp, true));
if (seedIndexes == null) return;
for (int[] i : seedIndexes) {
seeds.add(new CopyrightSeed(seedRegexp, i[0]));
}
}
private class CopyrightSeed {
private String seed;
private int index;
CopyrightSeed(String seed, int index) {
this.seed = seed;
this.index = index;
}
@Override
public String toString() {
return "CopyrightSeed{" +
"seed='" + seed + '\'' +
", index=" + index +
'}';
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy