-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 89489dd
Showing
7 changed files
with
122 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<groupId>com.ufes</groupId> | ||
<artifactId>ContadorDePalavras</artifactId> | ||
<version>1.0-SNAPSHOT</version> | ||
<packaging>jar</packaging> | ||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<maven.compiler.source>20</maven.compiler.source> | ||
<maven.compiler.target>20</maven.compiler.target> | ||
<exec.mainClass>com.ufes.contadordepalavras.ContadorDePalavras</exec.mainClass> | ||
</properties> | ||
</project> |
31 changes: 31 additions & 0 deletions
31
src/main/java/com/ufes/contadordepalavras/ContadorDePalavras.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license | ||
*/ | ||
|
||
package com.ufes.contadordepalavras; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
/** | ||
* | ||
* @author Kevin | ||
*/ | ||
public class ContadorDePalavras { | ||
|
||
public static void main(String[] args) { | ||
LeitorArquivo leitor = new LeitorArquivo(); | ||
ProcessadorTexto processador = new ProcessadorTexto(); | ||
EscritorArquivo escritor = new EscritorArquivo(); | ||
|
||
try { | ||
List<String> linhas = leitor.ler("exemplo.txt"); | ||
Map<String, Integer> frequenciaPalavras = processador.contarFrequenciaPalavras(linhas); | ||
escritor.salvarRelatorio(frequenciaPalavras, "relatorio.txt"); | ||
} catch (Exception e) { | ||
System.out.println("Falha: " + e.getMessage()); | ||
} | ||
} | ||
|
||
} | ||
|
26 changes: 26 additions & 0 deletions
26
src/main/java/com/ufes/contadordepalavras/EscritorArquivo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license | ||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template | ||
*/ | ||
package com.ufes.contadordepalavras; | ||
|
||
import java.nio.file.Files; | ||
import java.nio.file.Paths; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
/** | ||
* | ||
* @author Kevin | ||
*/ | ||
public class EscritorArquivo { | ||
public void salvarRelatorio(Map<String, Integer> frequenciaPalavras, String caminhoDestino) throws Exception { | ||
List<String> relatorio = new ArrayList<>(); | ||
for (Map.Entry<String, Integer> entrada : frequenciaPalavras.entrySet()) { | ||
relatorio.add(entrada.getKey() + ": " + entrada.getValue()); | ||
} | ||
Files.write(Paths.get(caminhoDestino), relatorio); | ||
} | ||
} | ||
|
20 changes: 20 additions & 0 deletions
20
src/main/java/com/ufes/contadordepalavras/LeitorArquivo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* | ||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license | ||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template | ||
*/ | ||
package com.ufes.contadordepalavras; | ||
|
||
import java.nio.file.Files; | ||
import java.nio.file.Paths; | ||
import java.util.List; | ||
|
||
/** | ||
* | ||
* @author Kevin | ||
*/ | ||
public class LeitorArquivo { | ||
public List<String> ler(String caminhoArquivo) throws Exception { | ||
return Files.readAllLines(Paths.get(caminhoArquivo)); | ||
} | ||
} | ||
|
27 changes: 27 additions & 0 deletions
27
src/main/java/com/ufes/contadordepalavras/ProcessadorTexto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license | ||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template | ||
*/ | ||
package com.ufes.contadordepalavras; | ||
|
||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
/** | ||
* | ||
* @author Kevin | ||
*/ | ||
public class ProcessadorTexto { | ||
public Map<String, Integer> contarFrequenciaPalavras(List<String> linhas) { | ||
Map<String, Integer> frequenciaPalavras = new HashMap<>(); | ||
for (String linha : linhas) { | ||
String[] palavras = linha.split(" "); | ||
for (String palavra : palavras) { | ||
frequenciaPalavras.put(palavra, frequenciaPalavras.getOrDefault(palavra, 0) + 1); | ||
} | ||
} | ||
return frequenciaPalavras; | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
oi oi oi oi | ||
oi oi oi oi | ||
ola ola ola |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
|