On 2 August 2013 11:52, Hady elsahar <[email protected]> wrote:
>> Scala uses implicit conversions, so instead of the explicit conversion
>> new RichFile(...) you can just import a method that does that
>> conversion and is declared as implicit. In this case,
>> RichReader.wrapReader.
>>
>> You can basically replace the three lines of
>> code above by one import and one statement:
>>
>> import org.dbpedia.extraction.util.RichReader.wrapReader
>>
>> IOUtils.readLines(file) { line =>
>> ...
>> }
>>
>> As another cosmetic change, you could also import IOUtils.readLines:
>>
>> import org.dbpedia.extraction.util.IOUtils.readLines
>> import org.dbpedia.extraction.util.RichReader.wrapReader
>>
>> readLines(file) { line =>
>> ...
>> }
>
>
> done that
> https://github.com/hadyelsahar/extraction-framework/blob/lang-link-extract/scripts/src/main/scala/org/dbpedia/extraction/scripts/LanguageSpecificLinksGenerator.scala
>
> except for in the second option "generating specific files" , i wanted to
> trigger the last line of code so i needed the  method  "hasNext" , so i
> couldn't use readlines defined method in IOUtils
>
>  val inFile = new File(args(1))
>  val inStream= IOUtils.inputStream(inFile)
>  val lines = Source.fromInputStream(inStream).getLines
>
> don't know , maybe we could add this to the functionality of IOUtils , i

I see. You are right, the current implementation of readLines makes
that very difficult.

There's an easy fix: RichReader.foreach [1] could use null as the
value of the last line, just like the BufferedReader it wraps. Simply
change these lines:

if (line == null) return
proc(line)

to this:

proc(line)
if (line == null) return

Of course, this is a breaking change, and we have to modify all the
code that uses IOUtils.readLines or RichReader.foreach to check for
null.

Or maybe we should change the signature of

(proc: String => U)

to

(proc: Option[String] => U)

and use None instead of null for the last line. Yeah, I guess that's
the Scala way. It also means that the code currently using readLines
and foreach won't compile anymore. Which is good.


JC



[1] 
https://github.com/dbpedia/extraction-framework/blob/dump/core/src/main/scala/org/dbpedia/extraction/util/RichReader.scala

> suggest also adding function WriteLine to IOUtils , to use it instead of
> LogtoFile method that i implemented
>
>
>
>> I just searched for introductions to Scala implicits, and I think this
>> one is pretty good:
>>
>> http://www.artima.com/pins1ed/implicit-conversions-and-parameters.html
>
>
> thanks for the link , it's good
>
>
> thanks
> Regards
>
> -------------------------------------------------
> Hady El-Sahar
> Research Assistant
> Center of Informatics Sciences | Nile University
>

------------------------------------------------------------------------------
Get your SQL database under version control now!
Version control is standard for application code, but databases havent 
caught up. So what steps can you take to put your SQL databases under 
version control? Why should you start doing it? Read more to find out.
http://pubads.g.doubleclick.net/gampad/clk?id=49501711&iu=/4140/ostg.clktrk
_______________________________________________
Dbpedia-developers mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/dbpedia-developers

Reply via email to