I tried to test how works the KBPTriplesAnnotation but result output is always empty. What I missed?
Code example:
Properties props = StringUtils.argsToProperties(args);
props.setProperty("annotators", "tokenize,ssplit,pos,lemma,ner,regexner,depparse,natlog,parse,mention,coref,kbp,openie,relation");
props.setProperty("regexner.mapping", "ignorecase=true,validpospattern=^(NN|JJ).*,edu/stanford/nlp/models/kbp/regexner_caseless.tab;edu/stanford/nlp/models/kbp/regexner_cased.tab");
StanfordCoreNLP pipeline = new StanfordCoreNLP(props);
IOUtils.console("sentence> ", line -> {
Annotation ann = new Annotation(line);
pipeline.annotate(ann);
for (CoreMap sentence : ann.get(CoreAnnotations.SentencesAnnotation.class)) {
sentence.get(CoreAnnotations.KBPTriplesAnnotation.class).forEach(System.out::println);
}
});
Related
public PartsServiceCombineModelDTO getServicePartsByModel(String model) {
ServiceInstance instance = loadBalancer.choose("PARTS_APP");
if (instance == null || instance.getUri() == null) {
throw new NoInstanceExistException("Part App Instance Not Available ");
}
String url = instance.getUri().toString();
ParameterizedTypeReference<List<PartsDTO>> responseType = new ParameterizedTypeReference<List<PartsDTO>>() {
};
HttpEntity<String> entity = new HttpEntity<>(new HttpHeaders());
ResponseEntity<List<PartsDTO>> response = restTemplate.exchange(url + properties.getPartModel() + model, HttpMethod.GET, entity, responseType);
List<CarService> service = repository.findAllByModel(model);
List<ServiceDTO> carsDto;
if (service.isEmpty()) {
throw new NoSuchCarExistException("Car Service Not Available");
} else {
carsDto = new ArrayList<>();
for (CarService car : service) {
ServiceDTO carDto = new ServiceDTO();
BeanUtils.copyProperties(car, carDto);
carsDto.add(carDto);
}
}
PartsServiceCombineModelDTO partsServiceCombineModelDTO = new PartsServiceCombineModelDTO(response.getBody(), carsDto);
return partsServiceCombineModelDTO;
}
Mutation Test Report
Here my test method which is not able to to mutate below topics
void getServicePartsByModel() {
when(properties.getPartModel()).thenReturn("/parts/model/");
ServiceInstance instance = mock(ServiceInstance.class);
when(instance.getUri()).thenReturn(URI.create("http://localhost:8080"));
when(loadBalancerClient.choose(eq("PARTS_APP"))).thenReturn(instance);
PartsDTO partsDTO = new PartsDTO();
partsDTO.setId("42");
partsDTO.setManufacturer("Manufacturer");
partsDTO.setMaterial("Material");
partsDTO.setModel("Model");
partsDTO.setPartName("Part Name");
partsDTO.setPartNumber("42");
partsDTO.setPrice(1);
partsDTO.setStock(1);
partsDTO.setWarranty("Warranty");
partsDTO.setYear(1);
PartsDTO partsDTO1 = new PartsDTO();
partsDTO1.setId("42");
partsDTO1.setManufacturer("Manufacturer");
partsDTO1.setMaterial("Material");
partsDTO1.setModel("Model");
partsDTO1.setPartName("Part Name");
partsDTO1.setPartNumber("42");
partsDTO1.setPrice(1);
partsDTO1.setStock(1);
partsDTO1.setWarranty("Warranty");
partsDTO1.setYear(1);
List<PartsDTO> parts = new ArrayList<>();
parts.add(partsDTO1);
parts.add(partsDTO);
ResponseEntity<List<PartsDTO>> partsResponse = ResponseEntity.ok(parts);
when(restTemplate.exchange(any(String.class), eq(HttpMethod.GET), any(HttpEntity.class), eq(new ParameterizedTypeReference<List<PartsDTO>>() {
}))).thenReturn(partsResponse);
List<CarService> carServices = new ArrayList<>();
CarService carService = new CarService();
carService.setCertified(true);
carService.setDealershipTrained(true);
carService.setId("42");
carService.setModel("Model");
carService.setOemParts(true);
carService.setServiceKM(1);
carService.setServiceMileage(1);
carService.setServiceName("Service Name");
carService.setServiceType(1);
carServices.add(carService);
when(serviceRepository.findAllByModel(eq(carService.getModel()))).thenReturn(carServices);
assertNotNull(carService);
verify(beanUtils, atLeastOnce());
BeanUtils.copyProperties(new CarService(),new ServiceDTO());
PartsServiceCombineModelDTO result = carServiceImpl.getServicePartsByModel(partsDTO.getModel());
}
Which throwing error :
Unnecessary stubbings detected.
Clean & maintainable test code requires zero unnecessary code.
Following stubbings are unnecessary (click to navigate to relevant line of code):
-> at com.example.carserviceapp.service.CarServiceImplTest.getServicePartsByModel(CarServiceImplTest.java:728)
-> at com.example.carserviceapp.service.CarServiceImplTest.getServicePartsByModel(CarServiceImplTest.java:731)
-> at com.example.carserviceapp.service.CarServiceImplTest.getServicePartsByModel(CarServiceImplTest.java:763)
-> at com.example.carserviceapp.service.CarServiceImplTest.getServicePartsByModel(CarServiceImplTest.java:778)
Please remove unnecessary stubbings or use 'lenient' strictness. More info: javadoc for UnnecessaryStubbingException class.
org.mockito.exceptions.misusing.UnnecessaryStubbingException:
Can Anyone Please help me in mutating the above method
BeanUtils.copyProperties(car, carDto); and
throw new NoSuchCarExistException("Car Service Not Available");
I'm trying to convert a normal code in a reactor write flow (i'm quite new with reactor), but I'm having problems and I don't know how to solve it.
public String magnetCreation(String name, MultipartFile file) {
// XLS file save
var xls = fileStorage.save(file);
// Excel Parsing
var data = excelParser.readFile(xls.toAbsolutePath().toString());
// Delete excel file
fileStorage.deleteFile(xls);
// Create one CSV file for each BH curve
List<MagnetBHCurveURL> urls = new ArrayList<>();
final MagnetDetails details = new MagnetDetails(name, false, List.of());
data.bhCurves().forEach(curve -> {
var csvFile = generateCSV(curve);
// Now the file name is generated on the fileserver
var savedName = fileServer.uploadFile(csvFile, uploadPath).block();
urls.add(new MagnetBHCurveURL(savedName, curve.temp));
});
log.info("URL csv upload: {}", urls);
// thing creation
var thingJsonObject = magnetUtility.createThing(details, data.summary(), urls);
var id = twinUtility.create(thingJsonObject);
// Return thingId
return id;
}
To this
public Mono<String> magnetCreation(String name, Mono<FilePart> file) {
var xlsElaborated = fileStorage.save(file).map(path -> excelParser.readFile(path.toAbsolutePath().toString()));
var urls = xlsElaborated.flatMapMany(data -> Flux.fromIterable(data.bhCurves()))
.flatMap(curve -> {
var csv = generateCSV(curve);
return fileServer.uploadFile(csv, uploadPath)
.map(url -> new MagnetBHCurveURL(url, curve.temp));
}).collect(Collectors.toList());
return Mono.zip(xlsElaborated, urls).map(x -> {
var mData = x.getT1();
var urlsLists = x.getT2();
final MagnetDetails details = new MagnetDetails(name, false, List.of());
return magnetUtility.createThing(details, mData.summary(), urlsLists);
}).flatMap(thingJsonObject -> twinUtility.createAsync(thingJsonObject));
Now this code works, but the excelParser.readFile is called twice, and I don't understand why.
I am writing a custom Code Refactoring to transform a variable declaration into a pattern matching expression including declaration. This works great but I cannot get the declaration part to work.
I succeed in transforming MyOwnClass myClass = GetCustomClass(); into:
if(GetCustomClass() is MyOwnClass)
{
}
I fail to transform MyOwnClass myClass = GetCustomClass(); into:
if(GetCustomClass() is MyOwnClass myClass)
{
}
The code I have:
Excerpt:
var generator = SyntaxGenerator.GetGenerator(document);
SyntaxNode isTypeExpression = generator.IsTypeExpression(method, type);
SyntaxNode ifClause = generator.IfStatement(isTypeExpression, new List<SyntaxNode>(), new List<SyntaxNode>());
editor.ReplaceNode(localDeclartionSyntax, ifClause);
Full code:
private async Task<Document> MakePatternMatchingClause(Document document, LocalDeclarationStatementSyntax localDeclartionSyntax, CancellationToken c)
{
if (document.TryGetSyntaxRoot(out SyntaxNode root))
{
var editor = new SyntaxEditor(root, document.Project.Solution.Workspace);
var declaration = localDeclartionSyntax.Declaration;
var variableDeclarationSyntax = localDeclartionSyntax.Declaration.Variables.FirstOrDefault();
TypeSyntax type = localDeclartionSyntax.Declaration.Type;
var method = variableDeclarationSyntax.Initializer.Value;
SyntaxToken identifier = variableDeclarationSyntax.Identifier;
var generator = SyntaxGenerator.GetGenerator(document);
SyntaxNode isTypeExpression = generator.IsTypeExpression(method, type);
SyntaxNode ifClause = generator.IfStatement(isTypeExpression, new List<SyntaxNode>(), new List<SyntaxNode>());
editor.ReplaceNode(localDeclartionSyntax, ifClause);
return document.WithSyntaxRoot(editor.GetChangedRoot());
}
return document;
}
With a fresh head in the morning I found the solution. One needs to use the older SyntaxFactory class (which I found before but I looked for the wrong keywords)
SingleVariableDesignationSyntax singleVariableDesignation = SyntaxFactory.SingleVariableDesignation(identifier);
DeclarationPatternSyntax singleVariableDeclaration = SyntaxFactory.DeclarationPattern(type, singleVariableDesignation);
IsPatternExpressionSyntax isPatternDeclaration = SyntaxFactory.IsPatternExpression(method, singleVariableDeclaration);
hi guys I have an existing pdf file that contain facture body I want to add text to this facture, I made a testing code to test how it works, but the code I wrote delete my original file and as a result the added text
private static final String FILE_PATH_NAME = "./src/main/resources/educart.pdf";
public void exportpdf(facture fact) {
Document document = new Document();
try {
PdfWriter.getInstance(document, new FileOutputStream(new File(FILE_PATH_NAME)));
//open
document.open();
// Paragraph 1 ->
Paragraph p = new Paragraph("This is a paragraph 1",
FontFactory.getFont(FontFactory.HELVETICA, 18, Font.BOLDITALIC));
document.add(p);
// Paragraph 2 ->
Paragraph p2 = new Paragraph();
p2.add("This is a paragraph 2");
p2.setAlignment(Element.ALIGN_CENTER);
document.add(p2);
// Paragraph 3 ->
Font f = new Font();
f.setStyle(Font.BOLD);
f.setSize(30);
f.setColor(255, 0, 0);
Paragraph p3 = new Paragraph("This is a paragraph 3", f);
p3.setAlignment(Element.ALIGN_RIGHT);
document.add(p3);
// Paragraph 4 ->
Paragraph p4 = new Paragraph("Grokonez",
FontFactory.getFont(FontFactory.HELVETICA, 250, Font.BOLDITALIC));
document.add(p4);
// Finish task ->
document.close();
System.out.println("Finish!");
} catch (DocumentException | FileNotFoundException e) {
e.printStackTrace();
}
}
orignal pdf file
result
PdfReader pdfReader =
new PdfReader("./src/main/resources/educart.pdf");
//Create PdfStamper instance.
PdfStamper pdfStamper = new PdfStamper(pdfReader, out);
I was trying to export my C# list to Csv file. All is set well. But the thing is field seperator is not working properly. its showing like, my string with " at the end (eg: 0000324df"). Here is my Controller code.
IEnumerable stockexpo = stockexp; // Assign value
MemoryStream output = new MemoryStream();
StreamWriter writer = new StreamWriter(output, Encoding.UTF8);
writer.Write("ItemNo,");
writer.Write("Repeat Count");
writer.WriteLine();
foreach (StockResult order in stockexpo)
{
writer.Write(String.Format("{0:d}", order.ItemNumber));
writer.Write("\"");
writer.Write(",");
writer.Write("\"");
writer.Write(order.Count);
writer.Write("\"");
writer.Write(",");
writer.WriteLine();
}
writer.Flush();
output.Position = 0;
return File(output, "text/comma-separated-values", "stockexp.csv");
I need to know how i can seperate the field values appropriately. Anyone can help me for this.
writer.Write("\"");
This line of code will be outputting a " every time. Why have it at all?
Also, I wouldn't have a comma before the WriteLine, since there is no need to delimit the end of the file.
IEnumerable stockexpo = stockexp; // Assign value
MemoryStream output = new MemoryStream();
StreamWriter writer = new StreamWriter(output, Encoding.UTF8);
writer.Write("ItemNo,");
writer.Write("Repeat Count");
writer.WriteLine();
foreach (StockResult order in stockexpo)
{
writer.Write(order.ItemNumber);
writer.Write(",");
writer.Write(order.Count);
writer.WriteLine();
}
writer.Flush();
output.Position = 0;
return File(output, "text/comma-separated-values", "stockexp.csv");